I'm having a bit of a block with part of my PowerShell script.
I have an array which contains users' email addresses and their compliance state. The same user may have multiple entries in the array as they are in multiple policies.
For example:
Username: User1, State: OK Username: User1, State: Not OK Username: User1, State: OK Username: User 2, State: OK Username: User 2, State: OK
What I need to do is merge all the entries for each user and then write their overall status to the screen. If all states are OK then report OK, but if Not OK is in any of their states report Not OK. For example:
User 1 - Not OK User 2 - OK
Any guidance is appreciated. Below is my code:
foreach ($Listing in $FullProtectionStatus) {
if ($listing.state -eq "compliant") {
Write-Host $Listing.userPrincipalName "compliant"
}
if ($Listing.state -eq "non compliant") {
Write-Host $Listing.userPrincipalName "not compliant" -ForegroundColor Red
}
}
UsernameandStateproperties of objects?