Count operating systems of computer accounts per AD domain.  Bonus function (take it or leave it) to test loading the AD module.  You can modify the Write-Host line at the end of the second function to build/append an array or hash table if you prefer.  This is just for demonstration.

function Load-AD-Module {
  Import-Module ActiveDirectory -ErrorAction SilentlyContinue
  if (!($?)) {
    Write-Host "Error: Must be run from an AD Domain Controller, or workstation with RSAT installed." -ForegroundColor Red -BackgroundColor Black


function Get-AD-OSList {
  $os = Get-ADComputer -Filter * -Properties operatingSystem | Select-Object -ExpandProperty operatingSystem | Select -Unique
  Return $os

function Get-AD-OSCounts {
  Write-Host "querying: Domain computer operating systems..."
  $oslist = Get-AD-OSList
  foreach ($os in $oslist) {
    $occ = 0
    $oc = Get-ADComputer -Filter "operatingSystem -eq `"$os`""
    if ($oc.length -gt 1) {
      $occ = $oc.Length
    elseif ($oc.GetType().name -eq 'ADComputer') {
      $occ = 1
    Write-Host "$occ = $os"



Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s