1

I have created a script to get the website status is running or stopped from IIS manager.

But i coudln't get exact output.

Question: just i need to display website status is running or stopped in IIS using scripts.

$serverList = 'SSCCL35' foreach ($server in $serverList) { $iis = Get-WmiObject Win32_Service -Filter "Name = 'sample'" -ComputerName $server if ($iis.State -eq 'Running') { Write-Host "IIS is running on $server" } Else { Write-Host "IIS is NOT running on $server" -ForegroundColor Red } } 

Note: "Sample" Service is running in my IIS. But i get output as "Not running".

1
  • You are querying IIS service status instead or website status. Check here. Commented Mar 10, 2017 at 10:44

1 Answer 1

2

The current example shows you looking for a service named "sample", not a site named "sample", which is why it's always stating that it's not running.

From the local IIS host, you could find it using AppCmd:

Invoke-Expression "$env:SystemRoot\system32\inetsrv\AppCmd.exe list site 'sample'" 

OR you could use the WebAdministration module to go pure Powershell (if it's available on the IIS host):

Import-Module WebAdministration; Get-WebsiteState -Name "sample" 

If you want to run the command on remote servers, you'll need to use Invoke-Command and add one of those lines to the ScriptBlock:

Invoke-Command -ComputerName $server -ScriptBlock {enter one of the above lines of code here} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.