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.

 

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!

 

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: I just got an email from Apple about money they owe me. It's real but the email ticks all the boxes for what scammers send … silly Apple.

 
6 comments
Short URL

Follow Up – List active directory users – This time in 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

Words of wisdom

Good job!
health insurance information  on July 24, 2010
This is a good piece of content I discovered your weblog looking around bing for a similar subject and arrived to this. I couldnt come across to much additional info on this article so it was great to locate this one. I probably will end up being returning to look at some other articles that you have another time.
Terrell Sures  on June 09, 2010
Hi ChrisI fumbled upon this articles of your's and I'm suffering bit of pain reading off members of a DistListItem.Long story cut short my current logic reads all 'Groups' from Global Address List - GAL (just the names). But now I'm stuck finding the members of these groups! I'd be very grateful for any help you could provide me with finding the members of a group once you've got the name of group from GAL? What I'm actually after is the mobile number of the members of group or an individual from GAL.Kind RegardsKunal
Kunal Patel  on February 25, 2010
Test User: No you don't need to be a domain administrator for this to work. A recent implementation that I used worked for everyone in the organisation (and obviously only a few were domain administrators). Try it as a domain admin and if it works it's a permissions issue at your site. You *do* need to be running the application as a user that's a member of the domain though unless you modify the code to use .NET impersonation (which it doesn't do at the moment).
chris  on February 17, 2010
HiDo I need to be domain administrator to be able to get a list of users in the domain.I am not an administrator and when I run this code I don't get any resultsThanks
Test User  on February 17, 2010
Thanks lot man its relay help flue .....
Karthik  on July 22, 2009

Hi!  Care to leave a comment?

Remember my personal information

Notify me of follow-up comments?

Please enter the word you see in the image below:


 

Digital Formula (that's ME!)

 

 
DigitalFormula is an experiment in HTML5 and CSS3 design by Chris Rasmussen, an amateur/casual designer based in Melbourne, Australia. -37.813611 144.963056