remotely Check the IIS status on multiple servers .

by mayank at 2013-03-18 03:07:42

Hi ,

I am new to powershell, and I need a script which can get me the state of IIS using a servers.txt file .

these servers are in the same domain.

the response would be of great help as we are into a production release and this script needs to be placed on the monitoring server .

Thanks
by simark at 2013-03-19 10:03:42
Hi mayank

Maybe you could try the following approach.
The prerequisite is that you feed the script with the computer names in the domain (or the computer names that you want to check)
You can use your text file that contains computer names (line by line) and get the content from that text file.
Note that this script does not check whether IIS is installed or not.
#Retrieve content from servers.txt
$servers = (Get-Content servers.txt)

#Now that you have the necessary computer names in the $servers variable you can check them one by one.
foreach($server in $servers)
{
#Store the IISADMIN Win32_Service object in $iis variable
$iis = Get-WmiObject Win32_Service -ComputerName $server -Filter "name='IISADMIN'"

#Check the current $iss.State
if($iis.State -eq "Running") {Write-Host "IIS is running on $server"}
else {Write-Host "IIS not running on $server"}
}

Another approach if you don’t want to use a text file you can import the Active directory module on a Windows Server (which is part of the domain of course) and use the Get-ADComputer cmdlet
Note that you can filter which computers you want fetch by specifying -filter criteria (-filter '’ will return all)
Import-Module ActiveDirectory
$computernames = Get-ADComputer -Filter '
' | Select -Expand Name
by MasterOfTheHat at 2013-03-19 14:33:52
If you are using v3 and don’t want to use Get-WmiObject, you can use Get-Service.

servers.txt:
tools01
sccm1
dc1

Get-Content -Path c:\temp\servers.txt | ForEach-Object { "$_ - $((Get-Service -ComputerName $_ -Name IISADMIN -ErrorAction SilentlyContinue).Status)" }

The limitation here is that you have to run that command as a user that has permissions to connect to those remote servers since Get-Service doesn’t have a -Credential parameter
by JasonHelmick at 2013-03-20 09:21:16
If you just want to check the WWW services – how about

PS C:> get-service W3SVC, WAS -ComputerName (Get-Content c:\servers.txt) | Select MachineName, Name, Status
by mayank at 2013-03-21 15:34:40
Thanks Guys.

The Approach given by simark worked for me !!