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.
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.
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.
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.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"
}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With