Hope this helps someone, it took me a bit to get the syntax down and understand why. (Yes, I’m still a PoSh newbie) I discovered when I was trying to write out a computer list retrieved from Active Directory, the output in the file was System.DirectoryServices.ResultPropertyValueCollection. After I added explicitly [String] $a in the code below, when the value was added to the file I specified, the actual ASCII value showed up. thought I would pass this alongQ $strCategory = “computer” $objSearcher.SearchRoot = $objDomain $colProplist = “name” $colResults = $objSearcher.FindAll() foreach ($objResult in $colResults) { Steve Schofield
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.Filter = (“(objectCategory=$strCategory)”)
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$objComputer = $objResult.Properties; $objComputer.name
[String]$a = $objComputer.name
Add-Content ss.txt $a
}
Cheers,
Helped me. Thanks. I was trying to figure the same. and came across your post.
LikeLike