我已经创建了一个脚本,以使网站状态运行或停止IIS管理器。
但我无法得到准确的输出。
问题:我只是需要显示网站状态,正在使用脚本在IIS中运行或停止。
$serverList = 'SSCCL35'
foreach ($server in $serverList) {
$iis = Get-WmiObject Win32_Service -Filter "Name = 'sample'" -ComputerName $server
if ($iis.State -eq 'Running') { Write-Host "IIS is running on $server" }
Else { Write-Host "IIS is NOT running on $server" -ForegroundColor Red }
}注意:“示例”服务正在我的IIS中运行。但我得到的输出是“不跑”。
发布于 2017-03-12 05:18:08
当前的示例显示您正在寻找一个名为"sample“的服务,而不是一个名为"sample”的站点,这就是为什么它总是声明它没有运行。
在本地IIS主机上,可以使用AppCmd找到它。
Invoke-Expression "$env:SystemRoot\system32\inetsrv\AppCmd.exe list site 'sample'"或者您可以使用WebAdministration模块进行纯Powershell (如果它在IIS主机上可用):
Import-Module WebAdministration; Get-WebsiteState -Name "sample"如果要在远程服务器上运行命令,则需要使用Invoke-Command并将其中一行添加到ScriptBlock中
Invoke-Command -ComputerName $server -ScriptBlock {enter one of the above lines of code here}https://stackoverflow.com/questions/42715736
复制相似问题