這段代碼將檢查列出的任何網站是否已經存在。
$sites = get-content -Path C:codeCheckSPSites.txt
foreach($site in $sites){
$url = (Get-SPOSite -Filter{url -like $site} -ErrorAction SilentlyContinue) -ne $null
if($url -eq $true){
Write-Host "$site already created" -BackgroundColor Red
}else{
Write-Host "$site not created" -BackgroundColor Green
}
當我使用變數$site來過濾搜索時,它并沒有找到這些網站。
我試著把變數放在引號里(Get-SPOSite -Filter{url -like "$site"),但也沒有效果。
如果有任何幫助,我們將不勝感激。
。多謝
uj5u.com熱心網友回復:
謝謝你Theo和UBK。將您的建議作為答案發布,以幫助其他社區成員。
你可以使用-Identity引數和站點集合的URL來查找存在的問題。
例如。Get-SPOSite -Identity https://contoso.sharepoint.com
# Verify if site of same name already exists in SharePoint Online.
$siteAlreadyExists = Get-SPOSite -Identity $url
# 如果存在,停止腳本。
if ($null -ne $siteAlreadyExists) {
Write-Host "site already exists" -ForegroundColor Red
...
}
如果你的代碼在網站不存在時失敗,那么你可以嘗試下面的try-catch塊:
try {
$siteAlreadyExists = Get-SPOSite -Identity $url
if ($null -ne $siteAlreadyExists) {
Write-Host "網站已經存在" -ForegroundColor Red
}
}
catch {
Write-Host "Site already exists" -ForegroundColor Red
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/326678.html
標籤:
下一篇:根據作業系統版本進行注冊表修改
