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

[玩转系统] SharePoint Online:使用 PowerShell 导出用户信息列表

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

SharePoint Online:使用 PowerShell 导出用户信息列表


要求:导出 SharePoint Online 中的用户信息列表。

SharePoint Online 中的用户信息列表存储有关用户的信息。它捕获用户元数据,例如用户图片、电子邮件、显示名称、登录名称等。当我们向用户授予权限时,它们会自动添加到隐藏的用户信息列表中。 SharePoint 从用户信息列表中检索字段的用户相关元数据,例如创建者、上次修改时间等。

如何将SharePoint Online中的用户信息列表导出到Excel?

您是否正在寻找从 SharePoint Online 导出用户信息列表的方法?在本指南中,我们将向您展示如何通过易于遵循的步骤来做到这一点!您将快速导出用户数据并准备在 Excel 中使用。导出的电子表格将包括用户的显示名称、电子邮件地址和上次登录日期等。

  1. 首先,打开 Microsoft Excel 桌面应用程序。
  2. 单击“数据”选项卡>>获取数据>>从其他来源> SharePoint列表(在某些版本中,位于:数据>>新查询>>从其他来源>>SharePoint列表)

    [玩转系统] SharePoint Online:使用 PowerShell 导出用户信息列表

  3. 输入您的 SharePoint Online 站点 URL 并单击“确定”

    [玩转系统] SharePoint Online:使用 PowerShell 导出用户信息列表

  4. 单击“Microsoft 帐户”>> 单击“登录”按钮登录 SharePoint Online,然后单击“连接”。

    [玩转系统] SharePoint Online:使用 PowerShell 导出用户信息列表

  5. 这将打开一个窗口,其中包含您网站上的所有可用列表。向下滚动并选择用户信息列表,然后单击“加载”。

    [玩转系统] SharePoint Online:使用 PowerShell 导出用户信息列表

这会将用户信息列表中的数据加载到 Excel 中,您可以查看和分析数据。

如何访问SharePoint Online中的用户信息列表?

如果您要访问 SharePoint Online 中的用户信息列表,请按照以下步骤操作:

  1. 首先,登录到您的 SharePoint Online 网站。接下来,单击左侧边栏中的“网站内容”链接。
  2. 进入网站后,将此 URL 附加到浏览器中的网站 URL 以获得“所有人”视图:/_catalogs/users/simple.aspx 例如,https://crescent.sharepoint .com/sites/Retail/_catalogs/users/simple.aspx

    [玩转系统] SharePoint Online:使用 PowerShell 导出用户信息列表

  3. 这将带您进入“用户信息”页面,其中包含您的 SharePoint Online 帐户中的所有用户的列表。

PowerShell 在 SharePoint Online 中导出用户信息列表

此 PowerShell 脚本将所有用户信息从任何 SharePoint Online 网站集的用户信息列表导出到 CSV 文件。


#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://crescent.sharepoint.com/sites/marketing"
$CSVPath = "C:\Temp\UserInfo.csv"

#Get Credentials to connect
$Cred= Get-Credential

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Get the User Information List
    $List=$Ctx.Web.SiteUserInfoList
    $FieldColl = $List.Fields
    $Ctx.Load($List)
    $Ctx.Load($FieldColl)
    $Ctx.ExecuteQuery()
 
    #Get All Items from User Information List
    $ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
    $Ctx.Load($ListItems)
    $Ctx.ExecuteQuery()

    #Array to Hold Result - PSObjects
    $ListItemCollection = @()
  
    #Fetch each list item value to export to excel
    ForEach($Item in $ListItems)
    {
        $ExportItem = New-Object PSObject 
        ForEach($Field in $FieldColl)
        {
            $ExportItem | Add-Member -MemberType NoteProperty -name $Field.InternalName -value $Item[$Field.InternalName]   
        }  
        #Add the object with property to an Array
        $ListItemCollection += $ExportItem
    }
    #Export data to CSV File
    $ListItemCollection | Export-Csv -Path $CSVPath -NoTypeInformation -Force

    Write-host "User Information List has been Exported to CSV!'" -f Green
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

该脚本生成以下 CSV 文件(顺便说一句,我已从 CSV 中删除了一些列!)

[玩转系统] SharePoint Online:使用 PowerShell 导出用户信息列表

使用 SharePoint Online Management Shell 从用户信息列表中导出用户数据:

SharePoint Online Management Shell 有一个 cmdlet Export-SPOUserInfo,用于从用户信息列表中导出用户数据。


#Connect to SharePoint Online
Connect-SPOService -Url https://crescent-admin.sharepoint.com

#Export User Info
Export-SPOUserInfo -LoginName [email protected] -site https://crescent.sharepoint.com/sites/marketing -OutputFolder "C:\Temp"

PnP PowerShell 从用户信息列表导出用户数据

我们有一个等效的 PnP PowerShell cmdlet Export-PnPUserInfo 用于从用户信息列表中导出用户数据:


#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

Export-PnPUserInfo -LoginName [email protected] -Site $SiteURL | ConvertTo-Csv | Out-File C:\Temp\Userinfo.csv

总之,可以使用几种方法(例如 Microsoft Excel、CSOM 或 PnP PowerShell)从 SharePoint Online 导出用户信息,以便您可以将数据用于报告、分析或导入到其他系统中。您选择的方法将取决于您的具体要求和您拥有的技术专业知识水平。

这是 SharePoint 本地部署的另一篇文章:如何在 SharePoint 中导出用户信息列表?

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

取消回复欢迎 发表评论:

关灯