如何启动IIS

时间:2017-02-24 17:17:09

标签: powershell iis

当我运行以下内容时:

$iis = get-wmiobject Win32_Service -ComputerName $env:computername -Filter "name='IISADMIN'

我一无所获。

如何验证IIS是否在Powershell中运行? 其次,如果我确定它没有运行,我该如何启动呢?

因为上面没有返回任何内容,我只能假设这意味着它没有运行,但我已经运行了IISReset并收到了输出:

  

试图停止......

     

互联网服务已成功停止

     

尝试开始......

     

互联网服务已成功重启

这意味着它正在运行,但另一个脚本表明它不是(其他脚本的source is here,并且我收到“它未运行”的消息。)

假设它没有运行,我该如何使用Powershell启动IIS?

安装了IIS。

1 个答案:

答案 0 :(得分:0)

首先检查服务是否已停止,然后在停止时启动它:

$service = Get-WmiObject Win32_Service -ComputerName 'myserver' -Filter "Name='IISAdmin'"
IF($service.State -eq 'Stopped')
{
Get-WmiObject Win32_Service -ComputerName 'myserver' -Filter "Name='IISAdmin'" | Start-Service
"Service started successfully"
}
elseif($service.State -eq 'Running')
{
"Service is already in running state"
}

除此之外,您可以查看Web Server (IIS) Administration Cmdlets

希望它有所帮助。

相关问题