Skip to content

Instantly share code, notes, and snippets.

@ctigeek
Created July 26, 2017 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctigeek/5f91ac17468c93f24582de6de455620b to your computer and use it in GitHub Desktop.
Save ctigeek/5f91ac17468c93f24582de6de455620b to your computer and use it in GitHub Desktop.
Enable dynamic IP throttling in IIS.
function Enable-DynamicIpThrottling($webSiteName, [bool] $enabled, [int]$maxRequests, [int]$intervalMilliseconds, [bool] $loggingOnly = $false) {
##https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/dynamicipsecurity/
Add-Type -Path "$env:SystemRoot\System32\inetsrv\Microsoft.Web.Administration.dll"
$manager = New-Object Microsoft.Web.Administration.ServerManager
$config = $manager.GetApplicationHostConfiguration();
$cpSecConfig = $config.GetSection("system.webServer/security/dynamicIpSecurity", $websiteName)
$cpSecConfig.SetAttributeValue("enableLoggingOnlyMode", $loggingOnly)
$requestRate = $cpSecConfig.ChildElements["denyByRequestRate"]
$requestRate.SetAttributeValue("enabled", $enabled)
$requestRate.SetAttributeValue("maxRequests", $maxRequests)
$requestRate.SetAttributeValue("requestIntervalInMilliseconds", $intervalMilliseconds)
$manager.CommitChanges()
$manager.Dispose()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment