Camera Icon

Got an event that needs shooting?  I've covered multiple events for marathon-photos.com and can capture the scenes & emotions that make your event unique.

Some samples of my own work are at Digital Formula on Flickr.

Wand Icon

Do you or your business need a website but you're unsure where to start?  Get in touch now and we'll get it sorted.

I focus on usable functionality & can setup smaller sites using Wordpress within hours of the order being placed.  Magic!

Globe Icon

So, you've already got a website but need help managing it?  I can help you.

Don't worry about knowing every single detail.  I'll find out the most important stuff and work with you to reach your goal, not someone else's.

said on twitter: LOL spammers really do bank on the ignorance of their targets huh? A file with a .jpg.exe extension ... really? http://t.co/0TgobjQc

 
Short URL
Warning: This article is older than 180 days and may contain inaccurate information.  Please use the information below at your own risk.

List active directory users – C#

From VB.NET to C#

In this article I’m going to carry on with the follow-ups to posts I wrote in the past about various topics. Today’s topic is still on the subject of using .NET to list the users in Active Directory although this time we’re going to do it in C#. I wrote the first post and sample application using VB.NET back when I (perhaps) didn’t know as much as I know now … hopefully y’all won’t be too harsh on my n00b code from back then. :)

So, what’s different? Apart from the language change here is a summary of what’s changed between this version and the original.

  • All references that aren’t needed have been removed.
  • The results are now added to a generic list of strings (the original was just an ArrayList).
  • The domain name can now be passed as a parameter on the command line. If one isn’t provided the user will be prompted.
  • Regular expressions are now used to filter out user accounts that don’t match certain criteria (the original did some horribly repetitive case-sensitive matching).
  • The output is now formatted better (the original was just a plain list).
  • The account’s email address is now shown too.
  • A total count of the accounts that can’t be ‘read’ is shown at the end.
  • The app’s exception handling is a whole heap better (the original, being a sample, didn’t have any).
  • The app won’t run if a domain name isn’t provided at all – an error message is displayed.

Note that this version doesn’t do any validation of the domain name e.g. length, illegal characters etc although you could use regular expressions to validate it.

On the next page is the entire source for the application – it’s a single .cs file.

1 2 Next »

» Tags: .net, c#, c#.net, active directory, list active directory users
DigitalFormula is an experiment in HTML5 and CSS3 design by Chris Rasmussen, an amateur/casual designer based in Melbourne, Australia. -37.813611 144.963056