Created
November 20, 2019 18:40
-
-
Save clintcolding/145af5dfcbbca2798d788a308fd459cd to your computer and use it in GitHub Desktop.
Perform various IIS App Pool tasks via PowerShell
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
#---- 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