【发布时间】:2015-10-08 03:08:15
【问题描述】:
我正在尝试编写一个 PowerShell 脚本,如果收到 503 响应代码,它将在 IIS 中重新启动应用程序池。
到目前为止,我已经设法在 IIS 的默认网站下检索每个 crm 应用程序的响应代码。但是,我不确定如何查找应用程序池名称。我尝试了以下方法,但它为每个站点返回相同的应用程序池。有人可以帮忙吗?
$getSite = (Get-WebApplication -Site 'Default Web Site')
$SiteURL = ForEach ($site in $getSite.path) {("http://localhost")+$site}
ForEach ($crm in $SiteURL){
$req = [system.Net.WebRequest]::Create($crm)
try {
$res = $req.GetResponse()
} catch [System.Net.WebException] {
$res = $_.Exception.Response
}
$ApplicationPool = ForEach ($app in $getSite.applicationpool) {$app}
if([int]$res.StatusCode -eq 503) {write-host ($crm + ' ' + [int]$res.StatusCode) + $app}
}
【问题讨论】:
标签: powershell iis