Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 136

Check if application pool is stopped and restart

$
0
0

Hello,
I'm try to create a powershell script for monitoring status of all application pools on my server, and if one is stopped, restart it.
The script is simple, but I try to stop one application pool (in IIS Manager this pool is stopped), but the script he sees it as started, no stopped :|

Can you help me ?

Import-Module WebAdministration
IIS:
Set-Location AppPools
$ApplicationPools = dir
foreach ($item in $ApplicationPools)
{
$ApplicationPoolName = $item.Name
$ApplicationPoolStatus = Get-WebAppPoolState $ApplicationPoolName
$ApplicationPoolStatusValue = $ApplicationPoolStatus.Value

#Write-Host "$ApplicationPoolName -> $ApplicationPoolStatusValue"

if($ApplicationPoolStatus.Value -ne "Started")
{
Write-Host "-----> $ApplicationPoolName found stopped."
Start-WebAppPool -Name $ApplicationPoolName
Write-Host "-----> $ApplicationPoolName started."
}
}


Viewing all articles
Browse latest Browse all 136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>