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

[玩转系统] SharePoint Online:使用 PowerShell 获取所有 SharePoint 组

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

SharePoint Online:使用 PowerShell 获取所有 SharePoint 组


要求: SharePoint Online PowerShell 列出网站集中的所有组。

使用 PowerShell 获取 SharePoint Online 组:Get-SPOSiteGroup

Get-SPOSiteGroup PowerShell cmdlet 显示特定网站集的所有现有 SharePoint 组的列表。使用 SharePoint Online Management Shell 控制台获取 SharePoint Online 中的用户组。

Get-SPOSiteGroup -Site

此 PowerShell cmdlet 可获取网站集中的所有 SharePoint 组、权限级别和用户。您可以通过访问组的角色属性来获取与网站集中每个组关联的权限级别。

SharePoint Online PowerShell 列出所有组

以下是从 SharePoint Online 网站获取所有组的 PowerShell 示例:


#Admin Center URL
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
 
#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)

#Get All Groups of a site collection
Get-SPOSiteGroup -Site "https://Crescent.sharepoint.com/sites/marketing"

让我们获取所有组、组权限和组用户


#Get Group Name, Role and Users
Get-SPOSiteGroup -site https://Crescent.sharepoint.com/sites/marketing | Select Title, Roles, Users

[玩转系统] SharePoint Online:使用 PowerShell 获取所有 SharePoint 组

SharePoint Online:使用 PowerShell 获取群组

使用带有 Group 参数的 Get-SPOSiteGroup cmdlet 来获取 SharePoint Online 网站中的组。


Get-SPOSiteGroup -Site "https://Crescent.sharepoint.com/sites/marketing" -Group "Marketing Owners"

将 SharePoint Online 组数据导出到 CSV:

让我们从 SharePoint Online 网站获取所有组并将组的数据导出到 CSV 文件。


#Admin Center & Site collection URL
$AdminCenterURL = "https://Crescent-admin.sharepoint.com/"
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"
$CSVPath = "C:\Temp\Groups.csv"

#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)

#Get All Groups of a site collection
$Groups = Get-SPOSiteGroup -Site $SiteURL
Write-host "Total Number of Groups Found:"$Groups.Count

$GroupsData = @()
ForEach($Group in $Groups)
{
    $GroupsData += New-Object PSObject -Property @{
        'Group Name' = $Group.Title
        'Permissions' = $Group.Roles -join ","
        'Users' =  $Group.Users -join ","
    }
}
#Export the data to CSV
$GroupsData | Export-Csv $CSVPath -NoTypeInformation 

用于获取组的 SharePoint Online PnP PowerShell

您可以使用 cmdlet Get-PnPGroup 从 SharePoint Online 网站获取所有组。以下是用于列出给定站点中的 SharePoint Online 组的 PnP PowerShell:


#Site collection URL
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"

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

#Get All Groups from the site - Exclude Hidden, Limited Access and SharingLinks Groups
Get-PnPGroup | Where {$_.IsHiddenInUI -eq $false -and $_.LoginName -notlike "Limited Access*" -and $_.LoginName -notlike "SharingLinks*"}

您还可以使用 Get-PnPSiteGroup cmdlet 来提供一些额外的组数据!


#Site collection URL
$SiteURL= "https://Crescent.sharepoint.com/sites/marketing"
$CSVPath = "C:\Temp\GroupData.csv"
 
#Connect to SharePoint Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get All Groups from the site - Exclude Hidden, Limited Access and SharingLinks Groups
$Groups = Get-PnPSiteGroup | Where { $_.LoginName -notlike "Limited Access*" -and $_.LoginName -notlike "SharingLinks*"}

$GroupsData = @()
ForEach($Group in $Groups)
{
    $GroupsData += New-Object PSObject -Property @{
        'Group Name' = $Group.Title
        'Permissions' = $Group.Roles -join ","
        'Users' =  $Group.Users -join ","
    }
}
#Export the data to CSV
$GroupsData | Export-Csv $CSVPath -NoTypeInformation 

这是另一篇从所有网站集中获取 SharePoint Online 组的文章:SharePoint Online:使用 PowerShell 的网站用户和组报告

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

取消回复欢迎 发表评论:

关灯