SharePoint-导出站点特定权限组的所有用户

641 阅读1分钟

开启掘金成长之旅!这是我参与「掘金日新计划 · 2 月更文挑战」的第1天,点击查看活动详情

使用Excel导出组内用户

  1. 登录SharePoint站点→点击站点设置→进入权限设置→点击目标组
  2. 找到URL中的MembershipGroupId=43,我们需要得到这个ID,现在这个ID是:43
  3. 构建获取组中用户的URL(将URL中的YOURSITE和GROUPID,替换成自己的值): https://YORSITE/_api/Web/SiteGroups/getbyid(GROUPID)/Users

image.png

image.png

image.png

  1. 打开Excel,在数据选项卡下,找到来自OData数据源。

image.png 5. 输入刚刚构建的URL,我的URL是 image.png 6. 点击OK,输入正确的账户密码,点击连接,加载数据,就可以在excel中看到刚刚导出的用户。

image.png

image.png

使用PowerShell组内用户

  1. 复制下面代码,用系统管理员身份打开powershell
  2. 替换代码中的SiteURL和GroupName。
  3. 运行代码,使用账户,密码登录以连接到SharePoint站点,输出结果。
```#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\PnP.PowerShell\1.11.0\Framework\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\PnP.PowerShell\1.11.0\Framework\Microsoft.SharePoint.Client.Runtime.dll"
 
#Config Variables
$SiteURL="https://udtrucks.sharepoint.com/sites/app-UDFormsAndTemplates-Dev"
$GroupName= "ACE User"
 
Try {
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials
     
    #Get the Group & Members of the group
    $Group = $Ctx.web.SiteGroups.GetByName($GroupName)
    $Ctx.Load($Group)
    $GroupUsers = $Group.Users
    $Ctx.Load($GroupUsers)
    $Ctx.ExecuteQuery()
 
    #Iterate through each User of the Group
    ForEach($User in $GroupUsers)
    {
        #get sharepoint online group members powershell
        $User | Select Title, Email
    }
}
Catch {
    write-host -f Red "Error Getting Group Users!" $_.Exception.Message
}


#Read more: https://www.sharepointdiary.com/2018/01/sharepoint-online-powershell-get-group-members.html#ixzz7szJ1jNFC
```js

image.png