vvlo2w
Last Updated: February 25, 2016
·
612
· jgemedina
9ceed3ede68b252b29127ddf840a36ef

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
      }
}
Say Thanks
Respond