我正在尝试快速检查网站是否存在。我的IF
语句中似乎有错误,但我不确定语法是否正确。这是我的代码:
$URLis = "https://ourdevsite.dev.com/sites/flibidyboots"
add-pssnapin microsoft.sharepoint.powershell -ea 0
IF ((Get-SPWeb $URLis) -ne 0){
Write-Host "Site does not exist, so we can proceed with building it" -foregroundcolor green
}
Else {
Write-Host "Site does exist, so we need to pick another URL" -foregroundcolor red
}
我出错了什么?
答案 0 :(得分:1)
好的,首先是它的$ null,而不是0.第二,如果它不是$ null它就存在,所以你的情况就混淆了。
答案 1 :(得分:0)
以下是一些可行的代码。
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
$url = "http://teams"
$w = Get-SPWeb -Identity $url -ErrorAction SilentlyContinue
if ($w) {
Write-Host "Site Exists" -ForegroundColor Green
} else {
Write-Host "No Site" -ForegroundColor Red
}