Copy Group Membership Permissions of a User in SharePoint using PowerShell

Requirement: Copy SharePoint Group Memberships of one user to another user

Solution: You can copy group memberships of one user to another user to have identical SharePoint Permissions for a SharePoint Site. Here is the PowerShell Script:
powershell to copy group membership permissions in sharepoint

PowerShell Script to copy Group Memberships from One user to another:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters


#Get the web
$web  = Get-SPWeb $SiteURL

#Get All group membershipss of the source user
$UserGroups = Get-SPUser $SourceUserID -web $SiteURL | Select -ExpandProperty Groups

#Get the Target User
$TargetUser = $web.EnsureUser($TargetUserID) 

#Add target user to each group
Foreach($GroupName in $UserGroups)
    Write-Host "Adding User to the Group:"$GroupName
    #Get the Group
    $Group = $Web.SiteGroups[$GroupName]
    #Add User to Group
Alternatively, to add a user to SharePoint group, you can use Set-SPUser cmdlet
Set-SPUser -Identity $TargetUser -Web $SiteURL -Group $GroupName
However, if the group doesn't has access to the site, you'll get an error message: "The specified group does not exist."

If you want to clone a particular user's permissions, use this PowerShell script:  PowerShell to Copy Permissions in SharePoint

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.