Last active
August 29, 2015 14:12
-
-
Save tany3/ec9e76a2032e36eeb9f8 to your computer and use it in GitHub Desktop.
PowerShell-StopSites
This file contains hidden or 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
# | |
#stop web site | |
# | |
$targetSiteNames = ( "WebSite1", "WebSite2" ) | |
$targetAppPools = ( "AppPool1", "AppPool2" ) | |
"Settings.Target Sites:" | |
foreach ($name in $targetSiteNames) { "`t" + $name } | |
"Settings.Target AppPools:" | |
foreach ($name in $targetAppPools) { "`t" + $name } | |
try{ | |
Import-Module WebAdministration | |
$webapps = Get-WebApplication | |
$list = @() | |
"Procedure:" | |
foreach ($webapp in get-childitem IIS:\AppPools\) | |
{ | |
$name = "IIS:\AppPools\" + $webapp.name | |
$item = @{} | |
$item.WebAppName = $webapp.name | |
$item.State = (Get-WebAppPoolState -Name $webapp.name).Value | |
if ($targetSiteNames -contains $item.WebAppName -And $item.State -eq "Started") | |
{ | |
Stop-Website $item.WebAppName | |
"`t" + $item.WebAppName + " - WebSite stopped." | |
} | |
if ($targetAppPools -contains $item.WebAppName -And $item.State -eq "Started") | |
{ | |
Stop-WebAppPool $item.WebAppName | |
"`t" + $item.WebAppName + " - AppPool stopped." | |
} | |
} | |
"Done." | |
} | |
catch | |
{ | |
$ExceptionMessage = "Error in Line: " + $_.Exception.Line + ". " + $_.Exception.GetType().FullName + ": " + $_.Exception.Message + " Stacktrace: " + $_.Exception.StackTrace | |
$ExceptionMessage | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment