Access detailed user account information in AD using VB.Net
https://www.mikesel.info/access-detailed-user-account-information-in-ad-using-vb-net/

Home » Access detailed user account information in AD using VB.Net

One of the challenges on large domains is keeping track of unused accounts, or checking to see if end users passwords have expired.  Now, I know there are several tools out and about that enable you to do this…But come on, where’s the fun in that!?

Using the code detailed below you can query active directory straight from a VB.Net application.

To use this code:

  1. Create a Form in vb.net, call it frmMain
  2. Add a text box to the form to handle the users name, call it txtUsername
  3. Add a text box to the form, set it to multiline = true, call it txtDetails
  4. Add a command button to the form, call it cmdGo
  5. Copy and paste the code below into the code editor
  6. Add a reference to the ‘System.DirectoryServices.AccountManagement’ .Net add-in
  7. Modify the line:

    To include your domain name and domain controllers name.  So, for instance, if your domain controller was called SBSserver, and your domain name was Dom1 then you would need to edit the line to read:

Now the code below is quite basic/limited but this gives you access to the currentADuser object, which you can use autocomplete to show you just what it can do. You may also notice that the code below is geared more towards searching more then one account.  This was extracted from a much larger project, after spending too long searching the net trying to find solutions to issues with the findall command.

If you do find the code useful and decide to use it in your project, drop me a comment below and let me know how it goes.

Home » Access detailed user account information in AD using VB.Net


  • Pingback: My Homepage()

  • Sam Raby

    Hi , thanks for this its helped me out . im just a bit stuck

    I’ve found that the code only returns the details when the full display name is given.

    How can i get it to search based on a partial name e.g ” John S” instead of “John Smith”

    • http://www.mikesel.info/ Mike Hudson

      Hi Sam

      What you need to do is use the ‘wildcard’ (*) in your search.

      It’s difficult to expand the code above, but if you post your code I will adjust it for you.

      Thanks
      Mike

  • Sam Raby

    Hi , thanks for this its helped me out . im just a bit stuck

    I’ve found that the code only returns the details when the full display name is given.

    How can i get it to search based on a partial name e.g ” John S” instead of “John Smith”

    • http://www.mikesel.info/ Mike Hudson

      Hi Sam

      What you need to do is use the ‘wildcard’ (*) in your search.

      It’s difficult to expand the code above, but if you post your code I will adjust it for you.

      Thanks
      Mike

  • Ryan Crane

    Hi Mike, just come across your article has helped me out big time. One quick question though how would I go about change the search criteria to the Username instead of the Alias?


Page 1 of 11

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Categories

* = required field

powered by MailChimp!