Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell脚本,用于获取网站在IIS管理器中是否正在运行或已停止的状态_Powershell - Fatal编程技术网

Powershell脚本,用于获取网站在IIS管理器中是否正在运行或已停止的状态

Powershell脚本,用于获取网站在IIS管理器中是否正在运行或已停止的状态,powershell,Powershell,我已经创建了一个脚本,从IIS管理器获取网站状态是正在运行还是已停止 但我无法得到确切的输出 问题:我只需要使用脚本显示IIS中正在运行或已停止的网站状态 $serverList = 'SSCCL35' foreach ($server in $serverList) { $iis = Get-WmiObject Win32_Service -Filter "Name = 'sample'" -ComputerName $server if ($iis.State -eq 'Running')

我已经创建了一个脚本,从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中运行。但是我得到的输出是“未运行”。

当前示例显示您正在查找名为“sample”的服务,而不是名为“sample”的站点,这就是为什么它总是声明它未运行的原因

从本地IIS主机,您可以使用
AppCmd
找到它:

Invoke-Expression "$env:SystemRoot\system32\inetsrv\AppCmd.exe list site 'sample'"
或者,您可以使用WebAdministration模块转到纯Powershell(如果IIS主机上有):

如果要在远程服务器上运行该命令,则需要使用
调用命令
,并将其中一行添加到
脚本块

Invoke-Command -ComputerName $server -ScriptBlock {enter one of the above lines of code here}
您正在查询IIS服务状态或网站状态。检查。
Invoke-Command -ComputerName $server -ScriptBlock {enter one of the above lines of code here}