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

[玩转系统] 如何在SharePoint Online中共享文档库?

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

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


要求:设置 SharePoint Online 文档库的权限。

如何授予对 SharePoint Online 中文档库的访问权限?

默认情况下,在 SharePoint 中创建的任何文档库都会继承其父网站的权限。但是,您有时可能必须共享对 SharePoint Online 中文档库的访问权限。在 SharePoint Online 中共享文档库使您可以与其他人实时协作并一起处理文件。在这篇文章中,我们将向您展示如何在 SharePoint Online 中共享文档库。

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

  1. 登录到您的 SharePoint Online 网站 >> 导航到您要更改权限的特定文档库。
  2. 单击“设置”齿轮 >> 选择“库设置”菜单项。这将带您进入库设置页面。

    [玩转系统] 如何在SharePoint Online中共享文档库?

  3. 单击“权限和管理”组下的“此文档库的权限”链接。

    [玩转系统] 如何在SharePoint Online中共享文档库?

  4. 单击功能区上的“停止继承权限”按钮并确认提示(如果文档库正在继承权限,顺便说一句!)。现在,您可以向文档库添加或删除用户和组以限制权限。

    [玩转系统] 如何在SharePoint Online中共享文档库?

  5. 选择用户和组,然后单击“删除用户权限”按钮,删除不需要的用户。要将其他用户添加到文档库,请单击“授予权限”并添加人员或组,然后设置必要的权限。

请注意,上述步骤要么提供对特定文档库的访问,要么限制对其的权限,而无需更改站点级别的任何权限。

PowerShell 向 SharePoint Online 中的文档库授予权限

我们还可以使用 PowerShell 授予对 SharePoint Online 中文档库的权限。以下是客户端对象模型 PowerShell,用于授予用户和组对文档库的访问权限:


#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"
    
#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"
$ListName ="Documents"
$UserID="[email protected]"
$GroupName="Retail Members"
$PermissionLevel="Edit"
 
#Get Credentials to connect
$Cred = Get-Credential

Try { 
    #Set up the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
  
    #get the List
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $Ctx.Load($List)
    $list.Retrieve("HasUniqueRoleAssignments")
    $Ctx.ExecuteQuery()

    #Break Inheritance if the list is inheriting permissions from parent
    If(!$List.HasUniqueRoleAssignments)
    {
        $List.BreakRoleInheritance($True, $false) #keep the existing permissions: Yes -  Clear list items permissions: No
        $ctx.ExecuteQuery()
    }

    #Grant Permission
    #Get the User
    $User = $Ctx.Web.EnsureUser($UserID)
    $Ctx.load($User)
    $Ctx.ExecuteQuery()
    
    #Get the Group
    $Group =$Ctx.Web.SiteGroups.GetByName($GroupName)
    $Ctx.load($Group)
    $Ctx.ExecuteQuery()
    
    #Get the permission level 
    $Role = $Ctx.web.RoleDefinitions.GetByName($PermissionLevel)
    $RoleDB = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Ctx)
    $RoleDB.Add($Role)
         
    #Assign permissions to list
    $UserPermissions =  $List.RoleAssignments.Add($User,$RoleDB)
    $GroupPermissions = $List.RoleAssignments.Add($Group,$RoleDB)
    $List.Update()
    $Ctx.ExecuteQuery()
    
    Write-host -f Green "Permission granted to List Successfully!"
}
Catch {
    write-host "Error: $($_.Exception.Message)" -Foregroundcolor Red
}

PnP PowerShell 限制对 SharePoint Online 中文档库的访问

我们可以使用 PnP PowerShell cmdlet Set-PnPListPermission 共享 SharePoint Online 中的文档库。以下是用于在 SharePoint Online 中设置文档库权限的 PowerShell:


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

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive
    
    #Get the List
    $List = Get-PnPList -Identity $ListName

    #Break Permission Inheritance of the Library - Remove all existing permissions
    Set-PnPList -Identity $ListName -BreakRoleInheritance

    #Grant Edit permissions on Library to User
    Set-PnPListPermission -Identity $ListName -AddRole "Edit" -User $UserID
 
    #Grant Read permission on document library to the Group
    Set-PnPListPermission -Identity $ListName -AddRole "Read" -Group $GroupName

}
Catch {
    Write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

同样,要通过删除现有用户和组来限制对文档库的访问,请使用:


#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName ="Branding"
$UserID = "i:0#.f|membership|[email protected]"
$GroupName = "Marketing Members"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive
    
    #Get the List
    $List = Get-PnPList -Identity $ListName
    $User = Get-PnPUser -Identity $UserID
    $Group = Get-PnPGroup -Identity $GroupName
 
    #Break Permission Inheritance of the Library - Remove all existing permissions
    Set-PnPList -Identity $ListName -BreakRoleInheritance -CopyRoleAssignments

    #Remove the user and group from document library permissions
    $List.RoleAssignments.GetByPrincipal($User).DeleteObject()
    Invoke-PnPQuery
    $List.RoleAssignments.GetByPrincipal($Group).DeleteObject()
    Invoke-PnPQuery
}
Catch {
    Write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

总之,在 SharePoint Online 中共享文档库是一个简单的过程,可以通过 SharePoint Online 用户界面或使用 PowerShell 来完成。通过执行本文中概述的步骤,您应该能够与特定用户或组共享 SharePoint Online 中的文档库并管理他们对库的访问。

如果要将文档库权限导出到 CSV 报告,请使用:SharePoint Online 文档库权限报告

经常问的问题:

如何在 SharePoint Online 中授予文件夹级别权限?

要授予文件夹权限,请浏览到该文件夹所在的 SharePoint Online 文档库 >> 单击“管理访问权限”>> 单击“高级”链接。单击“停止继承权限”>>,然后单击“授予权限”将用户添加到文件夹。
更多信息:在 SharePoint Online 中设置文件夹权限

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

导航到您的 SharePoint Online 站点,单击“设置”齿轮,然后单击“站点权限”,单击权限窗格上的“共享站点”按钮。如果是群组网站,您将看到“添加成员”按钮。键入用户名,然后选择权限级别以向用户授予网站权限。
详细信息:授予对 SharePoint 在线网站的访问权限

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

取消回复欢迎 发表评论:

关灯