This script is used to loop through all the application pools and will restart the application pools that are stopped
- function RestartApplicationPool
- {
- Clear-Host
- $webapps = Get-WebApplication
- [string] $list = @()
- foreach ($WebAppPools in get-childitem IIS:\AppPools\)
- {
- $name = "IIS:\AppPools\" + $WebAppPools.name
- $item = @{}
- $item.WebAppName = $WebAppPools.name
- $item.State = (Get-WebAppPoolState -Name $WebAppPools.name).Value
- if($item.State -eq 'Stopped')
- {
- Start-WebAppPool -Name $WebAppPools.name
- #$obj = New-Object PSObject -Property $item
- $list += $WebAppPools.name
- $list+=" and "
- }
- }
- if($list.Length -gt 0)
- {
- $list = $list.Remove( $list.Length - 4, 4 )
- }
- if($list.Length -gt 0) {
- Write-Host "Successfully restared the following " $list -ForegroundColor Green
- }
- else{
- Write-Warning "No application pools found to restart"
- }
- }
- RestartApplicationPool
This is how it will display the result, displays the Application pool that it starts
No comments:
Post a Comment