Use Powershell to Export IIS IP Restrictions to a File

If you ever find yourself needing to export a list of site or IP restrictions from a Windows based web server running IIS then this is how you do it using Powershell. 

I believe that there is a vbscript that can do this as well but I chose Powershell for this challenge and it worked so why not.

At this point I am assuming you know what Powershell is, have it installed and know how to execute scripts. With that being said.

Create a Powershell script and name the file “export-ip-restrictions.ps1” and paste in the text below.

Execute it and you should have a list of IP restrictions in the same folder as the script you ran.

Powershell Code Example

[string]$SitesVar = Read-Host "Enter Sitenames with no spaces in between, Seperated by ';' i.e site1;site2;site3" 
$exportfolder = Read-Host "Enter Export Folder i.e. C:\folder1" 
 
sl c:\windows\system32\inetsrv\ 
 
$a = 0 
$Sites = $SitesVar.Split(";") 
$count = $Sites.count 
 
do { 
foreach ($site in $Sites){ 
[xml]$out = .\appcmd.exe list config $site -section:system.webServer/security/ipSecurity  
 
$out."system.webserver"."security"."ipsecurity" | %{ 
$_.innerxml.split("<*>") | out-file $exportfolder\$site.txt 
 
} 
$a++ 
} 
} 
while ($a -ne $count) 

Author: Rick Cable / AKA Cyber Abyss

A 16 year US Navy Veteran with 25+ years experience in various IT Roles in the US Navy, Startups and Healthcare. Founder of FinditClassifieds.com in 1997 to present and co-founder of Sports Card Collector Software startup, LK2 Software 1999-2002. For last 7 years working as a full-stack developer supporting multiple agile teams and products in a large healthcare organization. Part-time Cyber Researcher, Aspiring Hacker, Lock Picker and OSINT enthusiast.

Leave a Reply