Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

Copy Group Memberships of a User in SharePoint using PowerShell

$
0
0
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

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>