The ADSI accelerator is fast, and built into PowerShell, unlike the Active Directory Module. When use it, or the ADSISearcher, you have results which look like this [Image from previous Microsoft URL]:
Getting the properties out to a file can be tricky. I wrote two little functions to make this easier:
Function ConvertTo-PSObjectFromDirectorySearchResult($oDS){ $outval = New-Object -TypeName PsObject foreach ($DC in $oDS){ foreach ($strProperty in $oDS.PropertiesLoaded){ $val = $DC.Properties[$strProperty] if ($val.GetTypeCode() -eq 'byte'){ $val = ByteToString ($val) }Else{ $val = [string]($val).trim() } Add-Member -InputObject $outval -MemberType NoteProperty ` -Name $strProperty -Value $val -Force } $outval } } Function ByteToString($v){ $ADPropVal='' #Delim character is used to join string of bytes $delim=";" if ($v.count -eq 1) {$v.tostring() }Else{ For ($i = 0; $i -le $v.count-1; $i++) { if ($v.item($i)) { $ADPropVal +=$v.item($i).ToString()+$delim } } } #Cleanup to remove trailing delimter $adpropval.TrimEnd($delim) }
Get-AllDNSServersInForest.ps1, demonstrates how to use these functions. It uses the ADSI accelerator to create the ADSI Searcher, then sends a list of all DNS servers in the forest to Out-Gridview, by using the query “(servicePrincipalName=DNS*)”