gpt4 book ai didi

powershell - 检查IIS是否安装

转载 作者:行者123 更新时间:2023-12-03 21:51:50 24 4
gpt4 key购买 nike

我正在编写一个 PowerShell 脚本来在 IIS 中托管一个网站。

我在没有安装 IIS 的机器上尝试了这个脚本,但出现错误,所以我想检查是否安装了 IIS,然后我想在 ISS 中托管一个网站。

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

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

最佳答案

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

关于powershell - 检查IIS是否安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47673926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com