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
无法使用Powershell从远程服务器获取IIS状态_Powershell - Fatal编程技术网

无法使用Powershell从远程服务器获取IIS状态

无法使用Powershell从远程服务器获取IIS状态,powershell,Powershell,我正在尝试使用powershell从远程服务器获取IIS状态。 我使用了命令Get Service,但是我没有从这个命令收到任何输出。 下面是我的代码块 $pass='pass'|ConvertTo-SecureString -AsPlainText -Force; $Credentials = New-Object System.Management.Automation.PsCredential("user",$pass); $Service=invoke-command -comp

我正在尝试使用powershell从远程服务器获取IIS状态。 我使用了命令Get Service,但是我没有从这个命令收到任何输出。 下面是我的代码块

$pass='pass'|ConvertTo-SecureString -AsPlainText -Force;
$Credentials =  New-Object   
System.Management.Automation.PsCredential("user",$pass);
$Service=invoke-command -computername "server" -credential $Credentials - 
scriptblock {Get-Service|Where-Object Name -eq 'IISADMIN'}
if($Service.Status -eq 'Running')
{
write-host "IIS Running"
}
else
{
 throw "IIS not running or Not installed"

}

我检查了您的代码,没有发现任何问题,您是否使用
Get service
或service Manager检查了本地存在的服务

无论如何,您不必使用
Invoke命令
为此,您可以使用
Get-Service
cmdlet的内置
-ComputerName
参数

如果需要提供凭据,可以使用WMI:

$Credential = New-Object System.Management.Automation.PsCredential($username, $encrypted)
$Service = Get-WmiObject -Class win32_service -ComputerName Server -Filter 'Name = "W3SVC"' -Credential $Credentials

尝试改用WMI调用,我发现它在处理远程服务器时更加可靠


$Service=Get WmiObject-Computername$computer-credentials$credentials Win32_Service-ErrorAction Continue |其中{$\uu.Name-eq'IISADMIN'}

什么是Windows服务器版本?如果它是Win2008R2,IIS服务实际上被称为:W3SVC(万维网发布服务)-只需查找此服务,而不是“IISADMIN”