Powershell Script for managing groups

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
April 27th, 2015 7:35am

This forum is for scripting questions, rather than script requests.

Please read the following first:
Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 1:59pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics