I'm trying to add a SharePoint group to a specific list that exists on all the sites in a collection. I would think this would be easier but I'm having difficulties. Inheritance is already broken on the list.
Below is my code and then the error I'm getting.
$siteNumbers = "2210"
$listsOnSite = "QWERTY"
Foreach($wnl in $siteNumbers)
{
$rootWeb = (Get-SPWeb ("http://url/to/site/" + $wnl))
Foreach($lst in $listsOnSite)
{
$list = $rootWeb.Lists[$lst]
$group = $rootWeb.Groups["Global Read-Only QWERTY"]
$role = $rootWeb.RoleDefinitions["Read"]
$roleAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($group)
$RoleAssignment.RoleDefinitionBindings.Add($role)
$rootWeb.RoleAssignments.Add($RoleAssignment)
$list.RoleAssignments.Add($roleAssignment)
$list.Update()
}
$rootWeb.Update()
}
New-Object : Constructor not found. Cannot find an appropriate constructor for type Microsoft.SharePoint.SPRoleAssignment. At line:9 char:33 + $roleAssignment = New-Object <<<< Microsoft.SharePoint.SPRoleAssignment( $group) + CategoryInfo : ObjectNotFound: (:) [New-Object], PSArgumentExce ption + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.C
ommands.NewObjectCommandException calling "Add" with "1" argument(s): "The permission level specified i s already added to the collection." At line:10 char:47 + $RoleAssignment.RoleDefinitionBindings.Add <<<< ($role) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
You cannot call a method on a null-valued expression. At line:12 char:30 + $list.RoleAssignments.Add <<<< ($roleAssignment) + CategoryInfo : InvalidOperation: (Add:String) [], RuntimeExcept ion + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression. At line:13 char:17 + $list.Update <<<< () + CategoryInfo : InvalidOperation: (Update:String) [], RuntimeExc eption + FullyQualifiedErrorId : InvokeMethodOnNull