Analyze Operating System by Organizational Unit

by Dec 22, 2015

Here is a quick script that scans all OUs in your Active Directory for computer accounts, then groups them per OU by operating system:

#requires -Version 2 -Modules ActiveDirectory

Get-ADOrganizationalUnit -Filter * |
  ForEach-Object {
    $OU = $_
    

    Get-ADComputer -Filter * -SearchBase $OU.DistinguishedName -SearchScope SubTree -Properties Enabled, OperatingSystem |
      Where-Object { $_.Enabled -eq $true } |
      Group-Object -Property OperatingSystem -NoElement |
      Select-Object -Property Count, Name, OU, OUDN |
      ForEach-Object {
        $_.OU = $OU.Name
        $_.OUDN = $OU.DistinguishedName
        $_
      }
  } |
  Out-GridView

Twitter This Tip! ReTweet this Tip!