Skip to content

Instantly share code, notes, and snippets.

@RickyLin
Created January 28, 2018 11:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickyLin/0fe4965eb4ce40cc1a43c02adba4d1ee to your computer and use it in GitHub Desktop.
Save RickyLin/0fe4965eb4ce40cc1a43c02adba4d1ee to your computer and use it in GitHub Desktop.
Powershell script to stop an IIS Application Pool
# usage: StopAppPool.ps1 -AppPoolName DefaultAppPool
# set-executionpolicy remotesigned
# Document of WebAdministration:
# https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/ee790599(v%3dtechnet.10)
# multiple parameters sample: param([string]$paramA,[string]$paramB)
param([string]$AppPoolName)
if ([string]::IsNullOrEmpty($AppPoolName))
{
throw "Parameter AppPoolName is required."
}
Import-Module WebAdministration
$AppPoolState = Get-WebAppPoolState -Name $AppPoolName
if ($AppPoolState.Value -eq "Started")
{
Stop-WebAppPool -Name $AppPoolName
Write-Output "$($AppPoolName) stopped."
}
else
{
Write-Output "$($AppPoolName) has already been stopped."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment