Hello Team,
I have a requirement to check if the users from three sites (Say A, B and C) are part two groups (say X and Y) or not.
Then if they are part of X then Remove Y and if not part of X then add Y.
The below is the code I tried but not working:
$CCsites = @("A","B","C")
$users = @()
foreach ($site in $CCSites)
{
$users = @(Get-QADuser -SearchAttributes {PerSiteName=$site} -properties * ) # persitename is the attribute that tell the site
}
foreach ($user in $users)
{
Get-QADUser -Identity $user |Where-Object {notMemberOf -like 'X'} | export-csv "data2.csv"| Add-QADGroupMember 'Y'
Get-QADUser -Identity $user -MemberOf 'X' | export-csv "data3.csv" |Remove-QADGroupMember 'Y'
}
Can anyone help me with a better one please.......
Regards,
Suman Rout
- Edited by Suman Rout 19 hours 28 minutes ago correction