I have a script snippet. This gives me an array with 2 propertys: Account and AccessRights. Now I want to build a foreach loop, but I also need to store the second value in a variable for further use.
So if I do:
foreach ($id in $ACLFile.Account) {
# do stuff
}
I only have the Account property saved in $id. But how can I also get its AccessRights value?
$ACLFile = GetNTFSAccess | select Account, AccessRights
$ACLGroup = $ACLFile | Group-Object Account
$Singles = $ACLGroup.Where({$_.Count -eq 1}).Group
$Duplicates = $ACLGroup.Where({$_.Count -gt 1})
$ItemizedDuplicates = $Duplicates | foreach {
[PSCustomObject][ordered]@{
"Account"=$_.Group.Account[0];
"AccessRights" = $_.Group.AccessRights -join ", "
}
}
@($ItemizedDuplicates, $Singles)