Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bentaylorwork/d30d2eb3b719cd080a9a3a1cc1ded083 to your computer and use it in GitHub Desktop.
Save bentaylorwork/d30d2eb3b719cd080a9a3a1cc1ded083 to your computer and use it in GitHub Desktop.
$adUsers = Get-AdUser -Filter * -Properties name, department
$uniqueDepartments = $adUsers | Where-Object { $_.department -ne $null } | Select-Object -ExpandProperty department -Unique
foreach ($uniqueDepartment in $uniqueDepartments) {
$variableSplat = @{
'Name' = ($uniqueDepartment -replace ' ', '')
'Value' = $adUsers | Where-Object { $_.department -eq $uniqueDepartment }
}
Set-Variable @variableSplat
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment