Skip to main content
 

This is an example of using the active-directory powershell module to query directory information.

This script produces a count of all employees (faculty and staff) by Connect Carolina division number as well as comma separated list consisting of {division number, employee account display name, onyen}

 

 

$sopGroups = @()
$counted = @()
$msg = ''
$sopOrg = @()


foreach ($a in get-adgroup -Filter {name -like "MSG_unc-org-45*-employee"} | SELECT Name){
  if ($a.Name -ne "MSG_unc-org-4501-employee"){
      $sopGroups += $a
  }
}

echo "---"
echo "# FTEs by Dept (no duplicates)"
echo "---"

foreach ($a in $sopGroups){
  $msg = $a.Name + " | "
  $count = 0
  foreach ($b in Get-ADGroupMember $a.Name -Recursive){
    if ($b.objectClass -eq "user"){
      if ($b.SamAccountName -notin $counted){
        $counted += $b.SamAccountName
        $count++
      }
      $deptNo = $a.Name.Replace("MSG_unc-org-","")
      $deptNo = $deptNo.Replace("-employee","")
      $sopOrg += $deptNo + "," + $b.name + "," + $b.SamAccountName
    }
  }
  $msg += $count
  echo $msg
}

echo "---"
echo "FTE DEPT Mapping"
echo "---"

foreach($a in $sopOrg){
  $a
}
Comments are closed.