Share via


PowerShell Tricks: Start/Stop IIS websites without the WebAdministration Module

Query: How to start or stop websites in IIS without using the WebAdministration PowerShell module?

Solution: One doesn't have to rely solely on the PowerShell module for web administration. Below is a code snippet which will start the "Default Web Site" for you:

try{    $ErrorActionPreference = "Stop" #To catch exceptions    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration") | Out-Null    $iis = new-object Microsoft.Web.Administration.ServerManager    $website = $iis.sites | Where {$_.name -eq "Default Web Site"} #filter the Website Object    $website.start() #invoke the start method on it      #$website.stop() # uncomment this line to stop the website}catch{    Write-Error -message "Couldn't start website."}

Hope this helps.

Other languages

This article is also available in the following languages: