Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Cannot find an appropriate constructor for type Microsoft.SharePoint.SPRoleAssignment

$
0
0

I am trying to use PowerShell to update the permission of groups in my sites, and I am using this script.

$ver = $host | select version
if($Ver.version.major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"}
if(!(Get-PSSnapin Microsoft.SharePoint.PowerShell -ea 0))
{
Write-Progress -Activity "Loading Modules" -Status "Loading Microsoft.SharePoint.PowerShell"
Add-PSSnapin Microsoft.SharePoint.PowerShell
}

$web = Get-SPWeb http://theSite
$group = $web.Groups["GroupOne Members"]
$role = $web.RoleDefinitions["Read"]

$RoleAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($group)
$RoleAssignment.RoleDefinitionBindings.Add($role)

$web.RoleAssignments.Add($RoleAssignment)
$web.Update()
$web.Dispose()

When I ran my script the first time and it worked just fine, however I am not getting the "Aconstructor was not found. Cannot find an appropriate constructor for type Microsoft.SharePoint.SPRoleAssignment." error when I run the same script for subsequent sites. I don't understand why it worked the first time, but won't work now...anyone ever run into this? 


Viewing all articles
Browse latest Browse all 7589

Trending Articles