Check whether IIS is installed or not Check whether IIS is installed or not powershell powershell

Check whether 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"}


I needed to do this for a list of several hundred servers today. I modified the previous answer to use get-service w3svc instead of WMI installed state. This seems to be working for me so far.

$servers = get-content  c:\listofservers.txtforeach($server in $servers){$service = get-service -ComputerName $server w3svc -ErrorAction SilentlyContinueif($service){Write-Host "IIS installed on $server"} else {Write-Host "IIS is not installed on $server"}}


In an elevated Powershell window this works for me:

On Windows Server 2012 (on Windows Server 2008 first run this: Import-Module ServerManager)

if ((Get-WindowsFeature Web-Server).Installed) {    Write-Host "IIS installed"} 

On Windows 10

if ((Get-WindowsOptionalFeature -Online -FeatureName "IIS-WebServerRole").State -eq "Enabled") {    Write-Host "IIS installed"}