Script do PowerShell para reiniciar um site e pool de aplicativos

Este script verificará primeiro se o módulo PowerShell adequado está instalado no sistema, caso contrário, avisará o usuário e sairá.

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
}
}