Powershell Aficionado

Recursively List all Windows Servers in OU

You can use the snippet below to list all of the systems in an organizational unit, OU, and below. The output lists the name of the server and the os version.

I use this and pipe the output to a text file that I can then review and update my server patch list.

$ou = "OU=MYOU,DC=Fabrikam,DC=com"
 Get-ADComputer -Filter {OperatingSystem -Like “Windows Server*”} -SearchBase $ou -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack -Wrap -Auto

In the above...

  1. change the $ou variable to match the LDAP path of your ou.
  2. The snippet looks for all systems that have an operating system string that begins with "Windows Server". You can change this to your liking as well.



Leave a Reply