简体   繁体   English

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

[英]Unable to fetch IIS status from Remote server using Powershell

I am trying to fetch IIS status from remote server using powershell. 我正在尝试使用Powershell从远程服务器获取IIS状态。 I have used command Get-Service but i don't recieve any output from this command. 我已经使用命令Get-Service,但是我没有从该命令接收任何输出。 Below is my code block. 下面是我的代码块。

$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"

}

I Checked your code and did not see any problem with it, Did you checked the service exists locally using Get-Service or Service Manager? 我检查了您的代码,但没有发现任何问题,您是否使用Get-Service或Service Manager检查服务在本地是否存在?

Anyway you don't have to use Invoke-Command for this, you can use the built in -ComputerName parameter of the Get-Service cmdlet, 无论如何,您不必为此使用Invoke-Command ,可以使用Get-Service cmdlet的内置-ComputerName参数,

And if you need to provide credentials, you can use WMI: 如果需要提供凭据,则可以使用WMI:

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

Try using a WMI call instead, I have found it far more reliable when working with remote servers. 尝试使用WMI调用,我发现使用远程服务器时它更加可靠。

$Service = Get-WmiObject -Computername $computer -Credential $credentials Win32_service -ErrorAction Continue | $ Service = Get-WmiObject-计算机名$ computer-凭据$ credentials Win32_service -ErrorAction继续| Where {$_.Name -eq 'IISADMIN'} 其中{$ _。Name -eq'IISADMIN'}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 powershell 从远程服务器获取服务状态 - Get service status from remote server using powershell 如何使用PowerShell从远程计算机获取所有(IIS)网站状态/状态? - How to get all (IIS) websites status/state from remote machine using PowerShell? 无法使用Powershell脚本从IIS服务从远程目录复制文件 - Unable to copy files from remote directory from IIS service using powershell script 如何使用Powershell在远程服务器上运行IIS应用程序池列表? - how to operate On List of IIS Application Pools On Remote Server Using Powershell? 使用Powershell从远程服务器安排任务 - Scheduled tasks from remote server using powershell 使用Powershell在远程计算机上重新启动IIS - Restart IIS on remote machine using Powershell 使用Jenkins的PowerShell脚本重置远程IIS - Reset Remote IIS with PowerShell script from Jenkins 我可以使用Powershell在远程IIS服务器上创建站点和应用程序池吗? - Can I create sites and application pools on a remote IIS server using Powershell? 使用 Powershell 从远程计算机获取从服务器安装的打印机 - Get printers installed from server from remote computer using Powershell 无法使用IIS Windows Server 2012将使用PHP脚本的Powershell电子邮件发送到Outlook - Unable to send powershell email using php script to outlook using iis windows server 2012
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM