PowerShell provides robust tools for managing IIS, including the IIS status. In Web Server Management, checking IIS status is a fundament administrative task.
Using the Get-Service
cmdlet in PowerShell, you can check the w3svc service status to verify the IIS status. The W3SVC is a Windows service that is responsible for making IIS work.
Checking the IIS status is significant for service health, ensuring the web server service is running and accessible.
The following PowerShell script checks the IIS status using the Get-Service cmdlet.
# W3SVC is the service name for IIS $iisService = 'W3SVC' #Retrieve the status of the IIS service $iisServiceStatus = Get-Service -Name $iisService # Check if IIS service is running if($iisServiceStatus -eq 'Running') { Write-Host 'IIS is running.' } else { Write-Host 'IIS is not running.' }
In the above PowerShell script, the Get-Service
command uses the Name
parameter to specify the IIS service name, in this case, ‘W3SVC‘, and stores the IIS status in the $iisServiceStatus
variable.
Later, it checks the condition if iis service status is equal to ‘Running’. if yes then print the message ‘IIS is running.’, else it prints ‘IIS is not running.’
The output of the above PowerShell script after verifying the IIS status is given below.
IIS is running
You can also check the IIS status using the Get-WmiObject
cmdlet that uses the Win32_Service
class to get the information about ‘W3SVC‘ specified by the Name
parameter on the local computer.
Get-WmiObject Win32_Service -Filter "Name = 'W3svc'" -ComputerName 'localhost'
The output of the above PowerShell script returns the W3SVC service information including its IIS status.
PS C:\> Get-WmiObject Win32_Service -Filter "Name = 'W3svc'" -ComputerName 'localhost'
ExitCode : 0
Name : W3SVC
ProcessId : 6096
StartMode : Auto
State : Running
Status : OK
Conclusion
I hope the above article on how to check IIS service status using the PowerShell Get-Service cmdlet is helpful to you.
Verifying the IIS status is very important to efficiently monitor the availability and health of web services running on the IIS server.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.