将用户添加到 SharePoint 文件夹对象时遇到以下错误:
使用“1”参数调用“添加”的异常:“集合具有固定大小。”
在 D:\User\Script1.ps1:114 char:17 $FPfolder.RoleAssignments.Add($assignment)
- CategoryInfo: NotSpecified: (:) [], MethodInvocationException
- FullyQualifiedErrorId : NotSupportedException
下面是我的代码片段:
ForEach ($FPfolderId in $FPfolderSplit)
{
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewXml = "@<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>$FPfolderId</Value></Eq></Where></Query></View>"
$FPfolder = $FPlist.GetItems($query)
foreach($role in $FPfolder.RoleAssignments)
{
if ($role.Member.Name.Equals($userToAction))
{
$FPfolder.BreakRoleInheritance($true)
$account = $web.EnsureUser("User1")
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$FPfolder.RoleAssignments.Add($assignment)
$FPfolder.Update()
}
}
}