IIS - IP Address and Domain Restriction Export How to export the IIS IP Address and Domain Restriction settings in a human-readable txt file with PowerShell

Exporting & Importing App Pools and Websites configuration between multiple IIS instances

If you're a web administrator and you often work with Internet Information Services (IIS), you most likely already know about the IP Address and Domain Restrictions, a great built-in feature of IIS8 that allows to selectively allow or deny access to the web server, websites, folders or files that makes your server more secure.

However, such feature comes with some major flaws: for example, we can't modify the single entries, for example to edit their IP address - we can only delete and add them again; furthermore, we can't add notes, descriptions or other meta-data to these entries, which would be very helpful to give an actual "name" to those IP addresses, thus preventing us from forgetting why we've put them there or which service (or person) they belong to. Last but not least, we are completely unable to print or export a human-readable list of the blocked (or allowed) IP addresses.

To fix the first two features we would need to develop a dedicated software with read and write permissions to some critical system files, which would be rather complex to implement: luckily enough, the "human-readable list" can be generated quite easily, since it only requires to issue a query to the appcmd.exe file, normalize the generated output and print it to a text file.

That's what this post is about: introducing IIS-RestrictedAddressList, a simple PowerShell script that can be used to export the IIS IP Address and Domain Restriction settings to a text list.

IMPORTANT: The updated source code is available on GitHub under MIT license. The above code is only the first version and has been added to this post for demonstration purposes only.
.

As we can see, the program allows to specify a single website or multiple (comma-separated) websites, and will print a text file containing a list of all the allowed or denied IP addresses, in the following format:

In the above file we can see the list for two different websites: website1.example.com and website2.example.com.

Conclusions

We hope that our PowerShell script will be useful to other web administrators that need to export a list of the IP Address and Domain Restriction feature - just like we did.

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.