Last active
July 26, 2017 14:08
-
-
Save ctigeek/5e49e7403dcc9be9b59bbffbe57301b5 to your computer and use it in GitHub Desktop.
Add an IP address to a black-list for an IIS website.
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
| 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