[英]set-sposite is working for individual sites but not in a loop
大家好,我可以使用以下命令分別設置租戶中的 sharepoint 站點敏感度標簽:
# Get the label (required ExchangeOnlineManagement module)
Connect-IPPSSession -userprincipalname wise@redacted
$c = Get-Credential wise@redacted
Connect-SPOService -Url https://redacted-admin.sharepoint.com -Credential $c -ModernAuth:$true -AuthenticationUrl https://login.microsoftonline.com/organizations
Set-SPOSite -identity {site_url} -SensitivityLabel:'{GUID of sens label here}'
現在我正在嘗試為所有未由用戶使用以下代碼手動設置的站點設置默認值 label,但它會拋出“站點已經有敏感度標簽”消息,這意味着 if 語句在從變量中的站點???
# Get the label (required ExchangeOnlineManagement module)
Connect-IPPSSession -userprincipalname wise@redacted
$c = Get-Credential wise@redacted
Connect-SPOService -Url https://redacted-admin.sharepoint.com -Credential $c -ModernAuth:$true -AuthenticationUrl https://login.microsoftonline.com/organizations
#Create a progress counter and fail counter
$count = 0
$fail = 0
#get all sites
write-host "Collecting site data" -ForegroundColor Yellow
$SiteCollections = Get-SPOSite -Limit All
write-host "Collecting site data - COMPLETED" -ForegroundColor Green
#get a count of total sites
$total = $SiteCollections.count
write-host "There are $total total sites." -ForegroundColor Green
foreach ($site in $SiteCollections){
$count++
try{
if ( $site.SensitivityLabel -eq '' ){
Set-SPOSite $site -SensitivityLabel:'{GUID}'
} else {
$label = $site.SensitivityLabel
Write-host "Site already has a sensitivity label: $label"
$site.Url | Out-File '.\Sites_already_labeled.txt' -Append
}
} catch {
$sitename = $site.Name
"Bad site: $sitename" | Out-File '.\Failed_change_sites.txt' -Append
$fail++
Write-Host "Failed site count = $fail" -ForegroundColor Blue
Write-Host "Failed site = $sitename" -ForegroundColor Blue
}
Write-Host "Processing Site $count of $total" -ForegroundColor Red
}
我已經在單個站點上測試了 if sens label = '',它確實滿足了 if 語句,所以我完全迷路了。
感謝 ChatGPT!
問題很可能與以下代碼行有關:if ( $site.SensitivityLabel -eq '' )。 SharePoint 在線站點的 SensitivityLabel 屬性在沒有應用 label 時可能不是空字符串。 相反,它可能是 $null,因此 if 語句應該更新為 if ( $site.SensitivityLabel -eq $null )。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.