Reputation: 337
Not sure if this is even possible, but I'm trying to compare properties of an ADgroup object and a PSCustomObject object. We're in the middle of a user audit which requires validating a list of active employees against our active AD user accounts along with their AD group memberships. Here's a basic breakdown of what I have so far:
(we're defining two separate search paths because we have groups in different OUs)
List of usernames from HR system
List of usernames from AD
Empty array to store custom object/properties
Compare HR to AD
$compareResults = compare-object -referenceobject $sourceUsers -differenceObject $ADUserName
Find group memberships of all matching users, create custom object, etc
foreach ($result in $compareResults) {
if ($result.SideIndicator -eq '==') {
$groupMem = get-adprincipalgroupmembership -identity $result.InputObject
}
$userObjEQ += [pscustomobject] @{
'UserName' = $result.InputObject
'Groups' = $groupMem.Name
}
}
From this point on, I want to compare every group from each matching user to the group name from the $mainGroups to see if there's a match. If there isn't then compare it to the $subGroups group names. If there's a match do nothing, if there's a mismatch, output the username along with any mismatched group names. Just not sure how best to compare these objects. Any hints will be appreciated.
Upvotes: 0
Views: 959
Reputation: 2935
If your groups are arrays, then use the -contains operator -- if they're not, make them arrays:
foreach ($u in $users) {
foreach ($groupdn in $u.memberof) {
if ($mainGroups -contains $ug -or $subGroups -contains $ug) {
## do something when the users' group exists in the checked sub-groups
}
}
}
...this assumes the $maingroups array is an array of group DNs...
Upvotes: 1