I got an e-mail today from a friend, he sent me this VB Script from the TechNet script center.
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")
strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC
Set objSitesContainer = GetObject(strSitesContainer)
objSitesContainer.Filter = Array("site")
For Each objSite In objSitesContainer
WScript.Echo "Name: " & objSite.Name
Next
He wanted to see if it could be done in Windows PowerShell. Immediately, I thought that get-ADSite would be his answer, but he doesn't have Exchange Server 2007 in his environment. Unfortunately Windows PowerShell doesn't currently have a bunch of AD specific cmdlets. There are a few third-party tools as well. There is a way to also do this with built-in tools and its really simple.
$forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$forest.get_Sites() | ft Name
I've tried this on both Windows Server 2003 and a Vista machine and it works!
Posted
Sep 28 2007, 06:12 PM
by
Joel Stidley