使用Powershell CSOM为Sharepoint组的列表添加只读权限 [英] Adding Read-Only-permissions to a list for a Sharepoint Group using Powershell CSOM
问题描述
我正在尝试为名为学生的特定组添加只读权限,以便创建名为测验的列表。我必须使用PowerShell CSOM,在我经历的其他每个教程中,都使用了.NET服务器类型。
代码:
I am trying to add read-only-permissions to a specific group called "Students" for a list I have created called "Quiz". I have to use PowerShell CSOM, and in every other tutorial I've been through, .NET server types have been used.
Code:
$ListName = "Quiz"
$PermissionLevel = "Read Only"
$web = $ctx.Web
$lists = $web.Lists
$ctx.Load($lists)
$ctx.ExecuteQuery()
foreach($list in $lists)
{
if($list.Title -eq $ListName)
{
$listId = $list.Id
}
}
$list = $lists.GetById($listId)
$ctx.Load($list);
$ctx.ExecuteQuery();
Write-Host "List:" $List.Title -foregroundcolor Green
if ($list -ne $null)
{
$groups = $web.SiteGroups
$ctx.Load($groups)
$ctx.ExecuteQuery()
foreach ($SiteGroup in $groups) {
if ($SiteGroup.Title -match "Students")
{
write-host "Group:" $SiteGroup.Title -foregroundcolor Green
$GroupName = $SiteGroup.Title
$builtInRole = $ctx.Web.RoleDefinitions.GetByName($PermissionLevel)
$roleAssignment = new-object Microsoft.SharePoint.Client.RoleAssignment($SiteGroup)
$roleAssignment.Add($builtInRole)
$list.BreakRoleInheritance($True, $False)
$list.RoleAssignments.Add($roleAssignment)
$list.Update();
Write-Host "Successfully added <$GroupName> to the <$ListName> list in <$site>. " -foregroundcolor Green
}
else
{
Write-Host "No Students groups exist." -foregroundcolor Red
}
}
}
我的错误在
My error is in
$roleAssignment = new-object Microsoft.SharePoint.Client.RoleAssignment($SiteGroup)
,我收到错误
, where I'm recieving the error
Cannot find an overload for "RoleAssignment" and the argument coun
t: "1".
大部分教程使用
Most tutorials use
$roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($SiteGroup)
我不能使用。
如何填写我的代码?
PS我知道我的代码有点乱,但我花了太多时间试图找到解决方案,而且我的代码在过去几小时内质量大大降低。对不起。
which I CAN NOT USE.
How can I complete my code?
P.S. I know my code is a bit messy, but I've been spending too much time trying to find a solution, and my code has greatly reduced in quality over the past hours. Sorry for that.
推荐答案
ListName = 测验
ListName = "Quiz"
PermissionLevel = 只读
PermissionLevel = "Read Only"
web =
这篇关于使用Powershell CSOM为Sharepoint组的列表添加只读权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!