Skip to content

Instantly share code, notes, and snippets.

@s-bauer
Created November 14, 2019 13:27
Show Gist options
  • Save s-bauer/f72d712a14bae0a36b8e2f4fe2ce689a to your computer and use it in GitHub Desktop.
Save s-bauer/f72d712a14bae0a36b8e2f4fe2ce689a to your computer and use it in GitHub Desktop.
List, Stop and Start IIS sites using powershell (Wrapper for appcmd)
function Get-IISSites() {
Set-Alias -Name "appcmd" -Value "$env:SystemRoot\System32\inetsrv\appcmd.exe"
$output = appcmd list site
if($LASTEXITCODE -ne 0) {
throw "You need to be Admin!"
}
$matches = $output | Select-String -pattern "(?<=SITE `").*?(?=`")" -AllMatches
return $matches | ForEach-Object { $_.Matches.Value }
}
function Stop-IISSite {
Param([string] $Name)
Set-Alias -Name "appcmd" -Value "$env:SystemRoot\System32\inetsrv\appcmd.exe"
appcmd stop site /site.name:$Name
if($LASTEXITCODE -ne 0) {
throw "Unable to stop site (Are you admin?)"
}
}
function Start-IISSite {
Param([string] $Name)
Set-Alias -Name "appcmd" -Value "$env:SystemRoot\System32\inetsrv\appcmd.exe"
appcmd start site /site.name:$Name
if($LASTEXITCODE -ne 0) {
throw "Unable to stop site (Are you admin?)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment