Instantly share code, notes, and snippets.

Embed
What would you like to do?
$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