Skip to content

Instantly share code, notes, and snippets.

@clintcolding
Created November 20, 2019 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clintcolding/145af5dfcbbca2798d788a308fd459cd to your computer and use it in GitHub Desktop.
Save clintcolding/145af5dfcbbca2798d788a308fd459cd to your computer and use it in GitHub Desktop.
Perform various IIS App Pool tasks via PowerShell
#---- Recycles all application pools on the given computer ----#
function RecyclePool {
[CmdletBinding()]
param (
[string[]]$ComputerName,
[pscredential]$Credential
)
process {
foreach ($server in $ComputerName) {
Invoke-Command $server -Credential $Credential {
Import-Module WebAdministration
$apps = Get-ChildItem iis:\apppools
foreach ($app in $apps) {
Restart-WebAppPool $app.name
}
[PSCustomObject]@{
Hostname = $env:COMPUTERNAME
AppPools = [string]$apps.Name
}
}
}
}
}
#---- Get the current stat of all application pools on the given computer ----#
function GetAppPoolState {
[CmdletBinding()]
param (
[string[]]$ComputerName,
[pscredential]$Credential
)
process {
foreach ($server in $servers.hostname) {
Invoke-Command $server -Credential $cred {
Import-Module webadministration
$apps = Get-ChildItem iis:\apppools
foreach ($app in $apps) {
[PSCustomObject]@{
Hostname = $env:COMPUTERNAME
AppPools = $app.Name
State = $app.State
}
}
}
}
}
}
#---- Start all stopped application pools ----#
function StartAppPool {
[CmdletBinding()]
param (
[string[]]$ComputerName,
[pscredential]$Credential
)
process {
foreach ($server in $servers.hostname) {
Invoke-Command $server -Credential $cred {
Import-Module webadministration
$apps = Get-ChildItem iis:\apppools
foreach ($app in $apps) {
if ($app.State -eq "Stopped") {
$app | Start-WebAppPool
[PSCustomObject]@{
Hostname = $env:COMPUTERNAME
AppPools = $app.Name
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment