Created
November 14, 2019 13:27
-
-
Save s-bauer/f72d712a14bae0a36b8e2f4fe2ce689a to your computer and use it in GitHub Desktop.
List, Stop and Start IIS sites using powershell (Wrapper for appcmd)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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