Copying group membership for bulk users

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 6 months ago.

  • Author
    Posts
  • #6287

    by southtx07 at 2013-02-22 14:54:28

    If anyone can give me advice on my script I'd greatly appreciate it. What I currently have I can copy group memberships from one account to another, but how do I modify to do a bulk copy? There has to be an easier way than listing out all the users (i.e -identity "user1", "user2", etc.). The user accounts are in a text file and there 200+ accounts. thanks

    $OldUser = Get-QADUser -Identity 'user1'
    $NewUser = Get-QADUser -Identity 'user1_adm'

    $users = Get-QADUser $OldUser |select memberof

    foreach($user in $users.memberof)
    {
    Add-QADGroupMember -Identity $user -Member $NewUser
    }

    by kittH at 2013-02-22 15:37:59

    You can use Get-Content to read the text file, and then a foreach loop to perform your action.. This is untested but should be pretty close:

    $OldUser = Get-QADUser -Identity 'user1'
    $NewUsers= Get-Content C:\Users.txt
    $Groups = Get-QADUser $OldUser | Select -ExpandProperty MemberOf
    Foreach($NewUser in $NewUsers)
    {
    foreach($Group in $Groups)
    {
    Add-QADGroupMember -Identity $Group -Member $NewUser -WhatIf
    }
    }

You must be logged in to reply to this topic.