I’m feeding the output from AD-GetUser into a hash list along the lines of:
$activeDirectory = @{}
Get-ADUser -Properties objectGUID,displayName,name,… |
ForEach-Object { $activeDirectory[$.objectGUID] = @{
distinguishedName = $.distinguishedName
name = $_.name
…
}
}
Is there a way to change the “distinguishedName = $.distinguishedName" (etc.) part of the code so that it builds dynamically based on the available values from the input? It would be nice if I added a property to the Get-ADUser list that I don’t have to add a new "property = $.property” entry.
Related but slightly different, I have:
$groups = @()
$activeDirectory.GetEnumerator() | ForEach-Object {
if ($($.Value.objectClass) -eq “group”) {
$groups += [pscustomobject]@{
objectGUID = $.Key
distinguishedName = $.Value.distinguishedName
displayName = $.Value.displayName
…
}
}
}
Again, is there a way to automate the value-processing part?
Thanks.