Skip to content

Instantly share code, notes, and snippets.

@AshFlaw
Created December 29, 2018 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshFlaw/73ab7d4a435bd023f857e1e685b7e12b to your computer and use it in GitHub Desktop.
Save AshFlaw/73ab7d4a435bd023f857e1e685b7e12b to your computer and use it in GitHub Desktop.
Use PowerShell to Monitor IIS Websites and Application Pools
$Servers = ''
Invoke-Command -ComputerName $Servers {
Import-Module -Name WebAdministration
$Websites = Get-Website
foreach ($Website in $Websites)
{
$AppPool = $Website.applicationPool
If ((Get-WebAppPoolState -Name $AppPool).Value -eq 'Stopped') {Start-WebAppPool -Name $AppPool}
$SiteState = $Website.State
If ($SiteState -eq 'Stopped') {Start-Website -Name $Website.Name}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment