One of the things I struggle is ‘syntax’ when it comes to scripting. This Powershell script is a combo of things I found to help filter which results are exported from Active Directory. Hope this helps.
$strCategory = “computer”
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
#$objSearcher.Filter = “(&(objectCategory=computer)(operatingsystemversion=5.2 (3790)))”
#$objSearcher.Filter = “(&(objectCategory=computer)(operatingSystem=Windows Server 2003))”
$objSearcher.Filter = “(&(objectCategory=computer)(operatingsystemversion=6.0 (6001)))”
$colProplist = “name”
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
$colResults | foreach {
$objItem = $_.Properties
$obj = new-object psobject
add-member -inp $obj noteproperty name $($objItem.name)
$obj
} | export-csv servers.csv -noType
Cheers,
Steve