2017-02-24 56 views
1

当我运行以下命令:?如何启动IIS

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

我什么也没得到

如何验证IIS已在PowerShell中运行 其次,我怎么启动,如果我确定它没有运行?

因为上面什么都没有返回,所以我只能假设这意味着它没有运行,但是我运行IISReset并收到了out放:

尝试停止...

互联网服务成功停止

试图开始...

互联网服务成功地重新启动

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

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

已安装IIS。

回答

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检查。

希望它有帮助。