Active Directory User Lookup Form

Download link at bottom of post.

I had some free time recently, so I decided I would write my first, hand-coded PowerShell form using Windows Forms. It took a bit to get started and feel comfortable, but before I knew it, I was adding some useful things to my form. My form’s purpose is to lookup users in Active Directory by their user logon name (think, SamAccountName) and return a specific set of properties — Name, Distinguished Name, Mail, Title, Department, and Office Phone.

Feel free to download, and use the form if you think it may be helpful. While there are a few things I’d like to add, and change, I think it’s a solid, version 1.0 effort. There’s a screen capture of the form in action below, and the download link is just beneath that.

In closing, I wouldn’t be surprised to find out that a tool, such as this, has already been developed and made available — I didn’t bother checking for that prior to writing this tool. I just wanted to completely write my own form in PowerShell with Windows Forms, and needed an idea.

Script Sharing - PowerShell Active Directory User Lookup Form01

Download the Active Directory User Lookup Form here: https://gist.github.com/tommymaynard/b833e7fa33dd76f2484b73db58a7d281

4 thoughts on “Active Directory User Lookup Form

  1. Michele

    Hi Tommy,
    i’m trying to use your form, but every samaccountname that i try to type I receive the message “Cannot locate user (user)

    any sugestion?
    thank you in advanced
    Michele

    Reply
    1. tommymaynard Post author

      Hi Michele,

      I downloaded the code from TechNet and ran it on my computer and it worked in my default Active Directory domain. This, as it had done back when it was authored. The form takes the value in the Username textbox, trims any empty space from both sides, and then run the following command: Get-ADUser -Identity $TextboxUsername.Text -Properties mail,Title,Department,OfficePhone,eduPersonPrimaryAffiliation. The value in $TextboxUsername.Text is the value you’ve entered. Perhaps try running the command I’ve included, replacing $TextboxUsernme.text with the user for which you’re searching. Do this in your PowerShell console, away from the form. If that works, but the form doesn’t then I’ll have to do some more thinking; however, I’m not sure what else it would be for now…

      Reply
  2. Mike

    Couldn’t get this working until i installed the RSAT powershell module, should be installed by default with windows nowadays, but wasnt for me for some reason.
    If you don’t see the script fetching your domain name in the topline description, you will get the “cannot find user” error.

    Reply
    1. tommymaynard Post author

      Thank you for the feedback, Mike. In retrospect, the form’s code should’ve probably checked for something like that itself. Thank you for pointing this out for future readers, however! I don’t think I’ll take the time to update this code unless it’s ever used in a production project, in which I’m working. Thanks again!

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *