繁体   English   中英

PowerShell-检查是否已安装IIS

[英]PowerShell - Check whether IIS is installed or not

我正在尝试编写一个脚本,该脚本确定Windows 10上是否安装了IIS。如果未安装IIS,我想为用户提供安装它并通过PowerShell进行安装。

我在这里看到了帖子: 检查是否已安装IIS

但是,当运行Get-WindowsFeature Web-Servernot recognized as the name of a cmdlet 因此,我尝试运行Get-WindowsOptionalFeature Web-Server但返回Get-WindowsOptionalFeature : A positional parameter cannot be found that accepts argument 'Web-Server'.

如何检查IIS是否已安装? 我该如何安装呢?

这未经测试,但似乎可行。 当然,您将必须决定要实际安装的功能。

$IIS = Get-WindowsOptionalFeature -Online -FeatureName “IIS-WebServer”
if ($IIS.State -eq "Disabled") { 
    Enable-WindowsOptionalFeature -FeatureName $IIS.FeatureName -Online
}

您可以使用Get-WindowsOptionalFeature -Online通过查看结果的State属性来确定启用了什么。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM