TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Find all the application pools that are stopped in IIS and restart
Dorababu Meka
Jul 19
2016
Code
1.3
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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
PowerShell
IIS
Application pools