Sunday, November 27, 2016

Copy Group Memberships 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 Script to copy Group Memberships from One user to another:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$SiteURL="http://intranet.crescent.com"

$SourceUserID="i:0#.w|Crescent\Salaudeen"
$TargetUserID="Crescent\Opera"

#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
    $Group.AddUser($TargetUser)
}
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



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!


You might also like:

Related Posts Plugin for WordPress, Blogger...