Note: This example is not commented very well. It is a compilation of different methods I found throughout many websites, including Microsofts, on coding around Active Directory (such as finding a username).

It is very sloppily put together and has very little comments.

I put this here as an example to hopefully save others a little bit of trouble from hunting down code based on the Active Directory.

For the most part, you can follow along if you're familiar with Active Directory. You'll need to know some information about your company setup and substitute the code where appropriate.

Again, it is very sloppy and there are a lot of commented out code which may or may not work (a lot of it does work if supplied the correct parameters) but at least you can see what Active Directory type coding is like.

For more details, see these posts which picked up on and continued with this example: