Created
December 25, 2014 10:07
-
-
Save tany3/eb6bc99646fd80634228 to your computer and use it in GitHub Desktop.
PowerShell-StartSites
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
# | |
#start 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 ($targetAppPools -contains $webapp.name -And $item.State -eq "Stopped") | |
{ | |
Start-WebAppPool $webApp.name | |
"`t" + $webapp.name + " - WebSite started." | |
} | |
if ($targetSiteNames -contains $webapp.name -And $item.State -eq "Stopped") | |
{ | |
Start-Website $webApp.name | |
"`t" + $webapp.name + " - AppPool started." | |
} | |
} | |
"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