我正在尝试快速检查网站是否存在。我的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
}我哪里搞错了?
发布于 2016-11-10 22:08:18
好的,首先它的$null,不是0。其次,如果它不是$null,它就存在,所以你的情况是混淆的。
发布于 2016-11-10 22:12:17
下面是一些可以工作的代码。
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
}https://stackoverflow.com/questions/40529544
复制相似问题