There are two groups in our environment 'contractors' and 'employees' , I need to write a script that lists all users who are not part of both the groups, can some one help me with it.
$n = Get-ADGroupMember "Contractor" | Sort-Object |
foreach {Get-ADUser $_.name | select name}
$group = "Employee"
foreach ($u in $n) {
$get = (Get-ADUser $u.Name -Properties * | Select-Object memberof)
if ($get.memberof -match $group) {
Write-Host $u.name " is ok. They're in both groups."
} else {
Write-Host $u.Name " is not a member" -ForegroundColor Red -BackgroundColor Yellow
}
}