Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Copy user groups of user to another user

$
0
0

Hi,

I have this so far but its obviously incorrect somewhere. Basically I need to export user groups of one user into a variable then add them to another user

Thanks

Import-Module ActiveDirectory

$SourceUser = Read-Host "Enter source username"
$DestinationUser = Read-Host "Enter destination username"

$cmd = Get-ADPrincipalGroupMembership -Identity $SourceUser

foreach ($Person in $cmd) {
    Add-ADGroupMember -Identity $DestinationUser -Members $Person.distinguishedname
}


Viewing all articles
Browse latest Browse all 8583

Trending Articles