adding multiple groups from User to a different User

I pulled a list of groups from one user and wanted to pipe them into another user

$Groups = Get-ADUser -Filter {displayname -eq "USERSRC"} -Properties memberOf |
    select memberOf

$User = Get-ADUser USERDEST


ForEach ($Group in $Groups) {

  Add-ADPrincipalGroupMembership $User  -MemberOf  $Group

}

I’m guessing there’s a question :slight_smile:

You’ll need to use Select-Object -ExpandProperty MemberOf when building the list of groups.

Also, it’s not wise to filter on the displayName attribute. This attribute has to be unique only within an OU, not within AD.

Ah! thanks for reading my mind as well as answering my question. I knew better about -expandProperty