大家好,这样我就可以在我的租户中设置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}'
现在,我尝试使用以下代码为所有未由用户手动设置的站点设置默认标签,但它抛出了“Site already has a sensitivity 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语句,所以我完全迷路了。
1条答案
按热度按时间py49o6xq1#
感谢ChatGPT!
问题很可能出在以下代码行中:if($site.SensitivityLabel -eq '')。SharePoint Online网站的SensitivityLabel属性在未应用标签时不能为空字符串。它可能为$null,因此if语句应更新为if($site.SensitivityLabel -eq $null)。