PowerShell Script to stop/start IIS in a machine

This PS script is useful since Sitecore Docker traefik  container does not like IIS running in a machine so, in your up.ps1 PS script, chuck this in before docker compose up since you might forget to stop iis manually and the script will take care of the exercise for you! 

# *******************************

# Stop IIS if running in this computer

$service=get-service w3svc  -ErrorAction SilentlyContinue

if ($null -ne $service.Name) {

if ($service.Status -eq 'Running') {       

$svcStatus=iisreset /stop

Write-Host "IIS Stopped..." -ForegroundColor Green

}

}

# *******************************


And, this one  does the converse of  starting IIS automatically:


# *******************************

# Start IIS if not running in this computer

$service=get-service w3svc  -ErrorAction SilentlyContinue

if ($null -ne $service.Name) {

if ($service.Status -ne 'Running') {

$svcStatus=iisreset /start

Write-Host "IIS Started..." -ForegroundColor Green

}

}

# *******************************

Comments