Powershell Script for managing groups RRS feed

  • Question

  • 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.......


    Suman Rout

    • Edited by Suman Rout Monday, April 27, 2015 11:40 AM correction
    • Moved by Bill_Stewart Tuesday, June 2, 2015 8:58 PM This is not "scripts on demand"
    Monday, April 27, 2015 11:33 AM