Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether IIS is installed or not

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

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

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

like image 455
reddy Avatar asked Dec 06 '17 12:12

reddy


People also ask

How do you check if IIS is installed or not?

To verify if IIS is installed, go to your 'Add or Remove Programs' utility in the Control panel and click on the 'Add/Remove Windows Components' in the side menu. On XP Pro and below, you should see an item called 'Internet Information Services (IIS)'. If this is checked, IIS should be installed.

How do I tell if IIS is installed on Powershell?

Start by hitting the WINKEY + R button combination to launch the Run utility, type in '%SystemRoot%\system32\inetsrv\InetMgr.exe' and hit Enter. Also, you can enter inetmgr and hit Enter to launch the same IIS Manager and follow the same steps as for the Command Prompt method.


2 Answers

if ((Get-WindowsFeature Web-Server).InstallState -eq "Installed") {
    Write-Host "IIS is installed on $vm"
} 
else {
    Write-Host "IIS is not installed on $vm"
}
like image 117
Joshua Avatar answered Oct 16 '22 08:10

Joshua


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.txt
foreach($server in $servers){
$service = get-service -ComputerName $server w3svc -ErrorAction SilentlyContinue
if($service)
{
Write-Host "IIS installed on $server"
} 
else {
Write-Host "IIS is not installed on $server"
}}
like image 22
Shortbus Avatar answered Oct 16 '22 07:10

Shortbus