Skip to content

Instantly share code, notes, and snippets.

@kclinden
Created December 15, 2020 21:59
Show Gist options
  • Save kclinden/bc38774d2fc24ac6cd51acde777dfed9 to your computer and use it in GitHub Desktop.
Save kclinden/bc38774d2fc24ac6cd51acde777dfed9 to your computer and use it in GitHub Desktop.
import-module webadministration
$name = "Block API Help"
$site = 'IIS:\Sites\Default Web Site'
$root = '/system.webServer/rewrite/rules'
$filter = "{0}/rule[@name='{1}']" -f $root, $name
Add-WebConfigurationProperty -pspath $site -filter $root -name "." -value @{name='Block API Help'; patternSyntax='Wildcard'; stopProcessing='True'}
Set-WebConfigurationProperty -pspath $site -filter $filter/match -name "url" -value "*"
Add-WebConfigurationProperty -pspath $site -filter $filter/conditions -name "." -value @{logicalGrouping="MatchAll"; input="{URL}"; pattern='/api/help/*'}
Set-WebConfigurationProperty -pspath $site -filter $filter/action -name "type" -value "CustomResponse"
Set-WebConfigurationProperty -pspath $site -filter $filter/action -name "statusCode" -value 403
Set-WebConfigurationProperty -pspath $site -filter $filter/action -name "subStatusCode" -value 0
Set-WebConfigurationProperty -pspath $site -filter $filter/action -name "statusReason" -value "Forbidden: Access is denied."
Set-WebConfigurationProperty -pspath $site -filter $filter/action -name "statusDescription" -value "You do not have permission to view this directory or page using the credentials that you supplied."
Start-Process "iisreset.exe" -NoNewWindow -Wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment