当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 授予列表或库权限

作者:精品下载站 日期:2024-12-14 14:14:40 浏览:15 分类:玩电脑

SharePoint Online:使用 PowerShell 授予列表或库权限


要求:提供对 SharePoint Online 中文档库的权限。

如何在SharePoint Online中共享文档库?

有时您可能希望向 SharePoint Online 中的用户和组授予列表或库级别的权限。例如,您可能希望提供站点级别的读取访问权限和单个列表级别的编辑权限。因此,要向列表和库授予权限,第一步,我们必须停止从其父级继承权限,然后将唯一的安全权限应用于网站集下的任何级别,例如子网站、列表、库或列表项。

如何授予对 SharePoint Online 中的列表或库的访问权限

如何在 SharePoint Online 中共享文档库?以下是如何向 SharePoint Online 中的文档库授予权限:

  1. 转到目标列表或库设置(在库页面中,单击功能区上的“库”选项卡 >> 选择列表设置。如果启用了新式 UI,请转到“站点连接”,然后从列表上下文菜单中单击“设置”)
  2. 在“列表设置”页面上,单击权限和管理组中的“此列表的权限”链接。
  3. 在权限页面上,如果列表从父级继承权限,我们必须打破权限继承。单击“停止继承权限”按钮。
  4. 现在,在功能区中,单击“授予”组中的“授予权限”按钮。
  5. 在共享对话框的指定文本框中输入姓名或电子邮件地址。

    [玩转系统] SharePoint Online:使用 PowerShell 授予列表或库权限

  6. 单击“显示选项”按钮并指定电子邮件邀请选项和适当的权限级别,例如编辑。
  7. 单击共享。

这为给定用户提供了对所选列表或库的权限。相同的过程适用于授予对 SharePoint Online 中的列表、库和单个项目的访问权限。

SharePoint Online:PowerShell 向用户或组授予列表或库的权限

可以使用 PowerShell 操作列表权限。下面是典型的 SharePoint Online 设置权限 PowerShell 脚本: 此脚本向现有 SharePoint 组授予给定列表的权限。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Configuration Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/Projects/"
$ListName="Project Documents"
$GroupName="Project Members"
$PermissionLevel="Read"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
  
    #Get the web and List
    $Web=$Ctx.Web
    $List=$web.Lists.GetByTitle($ListName)
    
    #Break Permission inheritence - keep existing list permissions & Item level permissions
    $List.BreakRoleInheritance($True,$True)
    $Ctx.ExecuteQuery()
    Write-host -f Yellow "Permission inheritance broken..."
    
    #Get the group or user
    $Group =$Web.SiteGroups.GetByName($GroupName) #For User: $Web.EnsureUser('[email protected]')
    $Ctx.load($Group)
    $Ctx.ExecuteQuery()

    #Grant permission to Group     
    #Get the role required
    $Role = $web.RoleDefinitions.GetByName($PermissionLevel)
    $RoleDB = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Ctx)
    $RoleDB.Add($Role)
        
    #Assign list permissions to the group
    $Permissions = $List.RoleAssignments.Add($Group,$RoleDB)
    $List.Update()
    $Ctx.ExecuteQuery()
    Write-Host "Added $PermissionLevel permission to $GroupName group in $ListName list. " -foregroundcolor Green
}
Catch {
    write-host -f Red "Error Granting Permissions!" $_.Exception.Message
}  

我们还可以使用 PnP PowerShell 在 SharePoint Online 中设置文档库权限。如果要向新的 AD 组/Office 365 组授予权限,请使用以下命令:


#Config Variables
$GroupName ="[email protected]" #Or Group ID

#Resolve the Group
$Group = $Web.EnsureUser($GroupName)
$Ctx.load($Group)
$Ctx.ExecuteQuery()

SharePoint Online:使用 PnP PowerShell 添加列表权限

让我们使用 PnP PowerShell cmdlet Set-PnPListPermission 将权限添加到 SharePoint Online 列表。


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/sites/Marketing"
$ListName ="Projects"
$UserID="[email protected]"
$GroupName = "Marketing Members"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Break Permission Inheritance of the List
Set-PnPList -Identity $ListName -BreakRoleInheritance -CopyRoleAssignments

#Grant permission on List to User
Set-PnPListPermission -Identity $ListName -AddRole "Edit" -User $UserID

#Grant permission on list to Group
Set-PnPListPermission -Identity $ListName -AddRole "Read" -Group $GroupName

同样,您可以使用此 PowerShell 将权限分配给列表中的组:


Set-PnPGroupPermissions -Identity $GroupName -List ListName -AddRole Contribute

从列表权限中删除用户或组:SharePoint Online:使用 PowerShell 从列表权限中删除用户或组

使用 Powershell 向外部用户授予列表访问权限

使用 PowerShell 脚本为外部用户设置 SharePoint Online 列表或文档库的权限。确保您在租户和网站集级别启用了外部共享。


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/retail"
$ListName ="Invoices"
$UserID="[email protected]"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
 
#Break Permission Inheritance of the List
Set-PnPList -Identity $ListName -BreakRoleInheritance -CopyRoleAssignments
 
#Grant permission on List to External User
Set-PnPListPermission -Identity $ListName -AddRole "Edit" -User $UserID

经常问的问题:

如何向 SharePoint Online 中的子网站授予权限?

如果子网站继承了父网站的权限,则中断子网站的权限继承。完成后,您可以通过以下方式授予对子网站的访问权限:设置>>网站权限链接。详细信息:如何授予对 SharePoint Online 中子网站的访问权限?

如何授予对 SharePoint Online 网站的访问权限?

导航到您的 SharePoint Online 站点 >> 单击“设置”齿轮 >> 单击“站点权限”>> 高级权限。在高级权限页面中,选择相关组,例如“ Owners”,单击“新建”>> 添加用户>> 输入用户名并单击“共享”。
更多信息:授予对 SharePoint Online 网站的访问权限

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯