PowerShell script to restart a Web Site and App Pool
This script will first verify that the proper PowerShell module is installed in the System, if not it will warn the user and exit.
if (-not(get-module -name "WebAdministration"))
{
if (-not(get-module -listavailable | where-object { $_.Name -eq "WebAdministration" }))
{
write-host "Web Administration Module not available, exiting..." -foreground red
}
else
{
write-host ">> Attempting to restart My Website..." -foreground cyan
write-host ""
import-module "WebAdministration"
stop-website MyWebsite
restart-webapppool MyWebsite
start-website MyWebsite
write-host ">> Done, check output for errors or hit any key to close this Window." -foreground cyan -nonewline
read-host
}
}
Written by Jorge Medina
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Powershell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#