Hi there
I am trying to list all servers in my single domain with the OU that they reside in and then export to either a .csv or txt file using Powershell. (Very new to Powershell).
I have so far managed to list all computers in the domain by using the following:
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher.Filter = ("OperatingSystem=Window*Server*")
$objSearcher.PropertiesToLoad.Add("Name") | Out-Null
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults) {
$objResult.Properties.name
}
Could anyone help with adding the OU information and how to export it out?
Thanks