Skip to content

Instantly share code, notes, and snippets.

@ctigeek
Last active July 26, 2017 14:08
Show Gist options
  • Select an option

  • Save ctigeek/5e49e7403dcc9be9b59bbffbe57301b5 to your computer and use it in GitHub Desktop.

Select an option

Save ctigeek/5e49e7403dcc9be9b59bbffbe57301b5 to your computer and use it in GitHub Desktop.
Add an IP address to a black-list for an IIS website.
function Add-IpToIisBlacklist($websiteName, $ip, $subnetMask = $null) {
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/ipSecurity", $websiteName)
$cpSecCollection = $cpSecConfig.GetCollection()
$newAdd = $cpSecCollection.CreateElement("add")
$newAdd["ipAddress"] = $ip
if ($subnetMask) {
$newAdd["subnetMask"] = $subnetMask
}
$newAdd["allowed"] = $false
$cpSecCollection.Add($newAdd) | Out-Null
$manager.CommitChanges();
$manager.Dispose()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment