Created
December 15, 2020 21:59
-
-
Save kclinden/bc38774d2fc24ac6cd51acde777dfed9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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