From:
http://www.sysadmins.eu/2015/02/copy-group-membership-to-another-user.html
因為memberof是object array,所以要select之後 轉給Add-AdroupMember
To get actual group membership for user John.Doe you can use:
get-aduser -identity John.Doe -properties memberof | select-object memberof -expandproperty memberof
To copy groups to another existing user use:
get-aduser -identity John.Doe -properties memberof | select-object memberof -expandproperty memberof | Add-AdGroupMember -Members Jane.Doe
If you wanna know what groups were copied:
get-aduser -identity Jane.Doe -properties memberof | select memberof -expandproperty memberof | Add-ADGroupMember -members John.Doe -PassThru
You can also copy groupmembership to multiple users:
get-aduser -identity Jane.Doe -properties memberof | select memberof -expandproperty memberof | Add-ADGroupMember -members John.Doe,Jack.Doe -PassThru