SHARE
TWEET

Untitled

a guest Oct 13th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $adUsers = Get-AdUser -Filter * -Properties name, department
  2.  
  3. $uniqueDepartments = $adUsers | Where-Object { $_.department -ne $null } | Select-Object -ExpandProperty department -Unique
  4.  
  5. foreach ($uniqueDepartment in $uniqueDepartments) {
  6.     $variableSplat = @{
  7.         'Name'  = ($uniqueDepartment -replace ' ', '')
  8.         'Value' = $adUsers | Where-Object { $_.department -eq $uniqueDepartment }
  9.     }
  10.  
  11.     Set-Variable @variableSplat
  12. }
RAW Paste Data
Top