检查是否已安装IIS [英] Check whether IIS is installed or not

查看:137
本文介绍了检查是否已安装IIS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写PowerShell脚本以在IIS中托管网站.

I am writing a PowerShell script to host a website in IIS.

我在没有安装IIS的计算机上尝试了此脚本,但出现错误,因此我想检查IIS是否已安装,然后要在ISS中托管网站.

I tried this script in a machine where there is no IIS installed and I got error so I want to check if IIS is installed and then I want to host a website in ISS.

下面是我正在尝试的脚本,但是它不起作用:

Below is the script I am trying but it is not working:

$vm = "localhost";
$iis = Get-WmiObject Win32_Service -ComputerName $vm -Filter "name='IISADMIN'"

if ($iis.State -eq "Running") {
    Write-Host "IIS is running on $vm"
} 
else {
    Write-Host "IIS is not running on $vm"
}

请使用任何PowerShell脚本帮助我检查是否已安装IIS.

Please help me with any PowerShell script to check if IIS is installed or not.

推荐答案

if ((Get-WindowsFeature Web-Server).InstallState -eq "Installed") {
    Write-Host "IIS is installed on $vm"
} 
else {
    Write-Host "IIS is not installed on $vm"
}

这篇关于检查是否已安装IIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆