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

[玩转系统] 使用 PowerShell 在 SharePoint Online 中获取用户有效权限

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

使用 PowerShell 在 SharePoint Online 中获取用户有效权限


要求:使用 PowerShell 获得在 SharePoint Online 网站上向用户授予的有效权限。

PowerShell获取用户在SharePoint Online中的有效权限

以下是如何使用“GetUserEffectivePermissions”方法检索特定用户在给定 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"

#Parameters
$SiteUrl = "https://salaudeen.sharepoint.com/sites/Retail"
$AdminAccount = "[email protected]"
$UserName = "[email protected]"

Try {
    # Connect to SharePoint Online
    $password = Read-Host -Prompt "Enter password" -AsSecureString
    $credential = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminAccount, $password)

    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    $ctx.Credentials = $credential

    #Get the site
    $web = $ctx.Web
    $ctx.Load($web)
    $ctx.ExecuteQuery()

    #get the User
    $User=$web.EnsureUser($UserName)
    $ctx.Load($User)
    $ctx.ExecuteQuery()

    # Retrieve the user permissions on the site
    $Permissions = $web.GetUserEffectivePermissions($user.LoginName)
    $ctx.ExecuteQuery()

    #get all base permissions granted to the user
    $PermissionKindObj=New-Object Microsoft.SharePoint.Client.PermissionKind
    $PermissionKindType=$PermissionKindObj.getType()

    ForEach ($PermissionKind in [System.Enum]::GetValues($PermissionKindType))
    {
        $hasPermisssion = $permissions.Value.Has($PermissionKind)
        if ($hasPermisssion)
        {
            Write-host $permissionKind.ToString()                    
        }
    }
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

此脚本获取给定站点上给定用户的所有权限,例如“AddListItems”、“EditListItems”、“DeleteListItems”等。

[玩转系统] 使用 PowerShell 在 SharePoint Online 中获取用户有效权限

我们可以使用此方法来检查用户对任何 SharePoint 对象(例如网站、列表或库、文件夹、列表项或文件)的权限。

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

取消回复欢迎 发表评论:

关灯