Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell - List all servers in the domain and the OU they reside in

$
0
0

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


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>