Created
August 7, 2015 00:13
-
-
Save felickz/f8a626a12a3850751fbe to your computer and use it in GitHub Desktop.
Stops an appPool and waits until it has entered the stopped state. By default the poll period is 1 second. This commandlet may take an AppPool object from the pipeline.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module WebAdministration | |
function Stop-WebAppPoolSafely | |
{ | |
<# | |
.SYNOPSIS | |
Stops an appPool and waits until it has entered the stopped state | |
.DESCRIPTION | |
Stops an appPool and waits until it has entered the stopped state. By default the poll period is 1 second. This commandlet may take an AppPool object from the pipeline. | |
.EXAMPLE | |
Stop-WebAppPoolSafely "APP_POOL_NAME" | |
Stops an appPool by name. | |
.EXAMPLE | |
Stop-WebAppPoolSafely -appPool $appPool | |
Stop the appPool object. | |
.EXAMPLE | |
$appPool | Stop-WebAppPoolSafely | |
Stop the appPool from the pipeline. | |
.EXAMPLE | |
$appPools | Stop-WebAppPoolSafely | |
Multiple appPools may be passed in through the pipeline. | |
.EXAMPLE | |
Stop-WebAppPoolSafely "APP_POOL_NAME" -poll 5 | |
Stop an appPool with a poll period of 5 seconds. | |
.EXAMPLE | |
Stop-WebAppPoolSafely "APP_POOL_NAME" -verbose | |
Stop an appPool with staus updates | |
.PARAMETER appPoolName | |
The name the appPool to stop | |
.PARAMETER appPool | |
The appPool to stop | |
.PARAMETER pollPeriod | |
The time period to wait between checking appPool status | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter(Position=0, ParameterSetName = 'name')] | |
[string]$appPoolName, | |
[Parameter(ValueFromPipeline=$true, ParameterSetName = 'appPool')] | |
$appPool, | |
[Parameter()] | |
[int]$pollPeriod = 1 | |
) | |
process | |
{ | |
if ($PSCmdlet.ParameterSetName -eq 'appPool') | |
{ | |
$appPoolName = $appPool.Name | |
} | |
if ( (Get-WebAppPoolState -Name $appPoolName).Value -eq "Stopped" ) | |
{ | |
Write-Warning "AppPool already stopped: $appPoolName" | |
return | |
} | |
Write-Verbose "Shutting down the AppPool: $appPoolName" | |
$currentState = (Get-WebAppPoolState $appPoolName).Value | |
Write-Verbose "$appPoolName is $currentState"; | |
# Signal to stop. | |
Stop-WebAppPool -Name $appPoolName; | |
do | |
{ | |
$currentState = (Get-WebAppPoolState $appPoolName).Value | |
Write-Verbose "$appPoolName is $currentState"; | |
Start-Sleep -Seconds $pollPeriod | |
} | |
until ( (Get-WebAppPoolState -Name $appPoolName).Value -eq "Stopped" ) | |
$currentState = (Get-WebAppPoolState $appPoolName).Value | |
Write-Verbose "$appPoolName is $currentState"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit to @jdpoligo