我找到了以下 Powershell 腳本。該腳本僅適用于匯出到 CSV 更改資料順序的操作。在 CSV 中,用戶首先出現,然后其他值出現在腳本中。我不再知道如何改變它。也許你們中有人有想法。
$AdminCenterURL = "https://contoso-admin.sharepoint.com/"
$CSVPath = "C:\Temp\sharepoint.csv"
Connect-SPOService -url $AdminCenterURL
$GroupsData = @()
Get-SPOSite -Limit ALL | ForEach-Object {
Write-Host -f Yellow "Processing Site Collection:"$_.URL
$SiteGroups = Get-SPOSiteGroup -Site $_.URL
Write-host "Total Number of Groups Found:"$SiteGroups.Count
ForEach($Group in $SiteGroups)
{
$GroupsData = New-Object PSObject -Property @{
'Site URL' = $_.URL
'Group Name' = $Group.Title
'Permissions' = $Group.Roles -join ","
'Users' = $Group.Users -join ","
}
}
}
$GroupsData | Export-Csv $CSVPath -NoTypeInformation -encoding utf8
Write-host -f Green "Groups Report Generated Successfully!"
匯出應按以下順序進行:
站點 URL、組名、權限,最后是所有用戶
uj5u.com熱心網友回復:
屬性在您的代碼中出現的順序是隨機的,因為您構造物件輸出的方式:一個從 Hashtable 獲取其屬性的新物件。(在 Hashtable 中@{},屬性沒有固定的順序)
您可以輕松地更改它以通過輸出來生成您需要的訂單PsCustomObjects。
下面,還直接捕獲變數中的輸出$GroupsData,這是比 =在陣列上使用加法更好的方法。
$GroupsData = Get-SPOSite -Limit ALL | ForEach-Object {
Write-Host "Processing Site Collection: $($_.URL)" -ForegroundColor Yellow
$SiteGroups = Get-SPOSiteGroup -Site $_.URL
Write-host "Total Number of Groups Found: $($SiteGroups.Count)"
foreach($Group in $SiteGroups) {
[PsCustomObject]@{
'Site URL' = $_.URL
'Group Name' = $Group.Title
'Permissions' = $Group.Roles -join ","
'Users' = $Group.Users -join ","
}
}
}
$GroupsData | Export-Csv $CSVPath -NoTypeInformation -Encoding utf8
使用Select-Object也可以實作相同的目的:
$GroupsData = Get-SPOSite -Limit ALL | ForEach-Object {
# store this url in a variable first
$siteUrl = $_.URL
Write-Host "Processing Site Collection: $siteUrl" -ForegroundColor Yellow
$SiteGroups = Get-SPOSiteGroup -Site $siteUrl
Write-host "Total Number of Groups Found: $($SiteGroups.Count)"
foreach ($Group in $SiteGroups) {
$Group | Select-Object @{Name = 'Site URL'; Expression = {$siteUrl}},
@{Name = 'Group Name'; Expression = {$_.Title}},
@{Name = 'Permissions'; Expression = {$_.Roles -join ","}},
@{Name = 'Users'; Expression = {$_.Users -join ","}}
}
}
$GroupsData | Export-Csv $CSVPath -NoTypeInformation -Encoding utf8
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/403374.html
標籤:
上一篇:優化代碼以提高性能并減少執行時間
