Troubleshooting the client’s current Active Directory site

I’ve seen a nice tweet a few weeks ago about how to get the client’s current Active Directory Site.

I cannot remember who tweeted it. Kudos to him/her, it’s very handy.

[DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite(
).Name

Of course, there are other (ugly) ways to get it, using gpresult.exe

gpresult /R /scope computer| 
Select-String -Pattern "Site\sName" |
Out-String | 
ConvertFrom-Csv -Delimiter ":" -Header "Property","Value"

… or using nltest.exe

((nltest /DSGETSITE) -split "`n")[0]

The .Net way is now definetly my favorite 😀

I wondered how far this System.DirectoryServices.ActiveDirectory.ActiveDirectorySite .Net class is available?

I could have find the answer using the following MSDN page:

…but my first attempt was the hard way :\
I remembered that I could easily get the Dll a cmdlet is loaded from with the Get-Command cmdlet:

Get-Command -Name Get-Command | fl Dll


How can I get the same info for a .Net class?

 [System.Reflection.Assembly]::GetAssembly(
 [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]
 ) | fl Location

So, the answer is that the System.DirectoryServices.ActiveDirectory.ActiveDirectorySite .Net class is available as of .Net version 2.0 on any (domain joined) client. Cool, isn’t it? 😎

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s