While constructing a page for the forest and domain functional levels, and the maximum functional level for domain controllers, I wanted to show an example of how to retrieve this Active Directory attribute for all domain controllers. You could for example incorporate this in your automated procedures to check for any Windows 2003 servers and take further actions when needed.
The script is below. It outputs object so you use the pipe for further processing. For information on the possible values for msDS-Behavior-Version check out the new AD Functional Levels page here.
#-------------------------------------------------------------------------------- # Name : Get-DCMSDSBehaviorVersion.ps1 # Created By : Michel de Rooij # E-mail : michel@eightwone.com # Date : 20120307 # Source : http://eightwone.com # Version : 1.0 # # THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK # OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. #-------------------------------------------------------------------------------- $RootDSE= [ADSI]'LDAP://RootDSE' $objSearchRoot= New-Object DirectoryServices.DirectoryEntry( "LDAP://"+ $RootDSE.configurationNamingContext) $objSearch= New-Object DirectoryServices.DirectorySearcher $objSearch.SearchRoot= $objSearchRoot $objSearch.Filter= "(objectClass=nTDSDSA)" $objSearch.SearchScope = "SubTree" $Results= @() $objSearch.FindAll() | ForEach { $objItem = $_.getDirectoryEntry() $obj= New-Object PSObject -Property @{ Servername= $objParent = $objItem.psbase.parent.DNSHostName.ToString() MSDSBehaviorVersion= $objItem.Get("MSDS-Behavior-Version") } $Results+= $obj } $Results
Note that if you have over 1000 domain controllers, you need to set the $objSearch.Pagesize, e.g. 1000. It may also encounter problems in forests with multiple roots.
Pingback: Exchange 2013 Preview: Prerequisites | EighTwOne (821)