[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Restrict IIS websites by IP

Posted on 2013-01-27
2
Medium Priority
?
1,017 Views
Last Modified: 2013-02-27
HI

Running Windows 2008 Server/ IIS 7. I need to restrict access to a particular site from the web server - the restriction should be based on IP. There are about 30 IP addresses only we want to allow, they are in a file named IP_Safe.csv

I've seen this article here: http://www.hrzdata.com/node/46

Which shows how to do this manually.

But we have about 30 servers, is there any way to automate this via Powershell?
0
Comment
Question by:neil4933
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 38824221
Here is a quick how to :


http://technet.microsoft.com/en-us/library/cc733090%28v=ws.10%29.aspx


You can simply loop the command indicated in a powershell script.
0
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 2000 total points
ID: 38824260
in your csv file, have each ip in different line, without headers
create servers.txt file contains all server names in each line.

cls
[Object[]] $ipArray = @()
gc c:\temp\IP_Safe.csv | %{
	$ipArray += $_
}

gc c:\temp\servers.txt | %{
	$server = $_
	
	#get iis object
	$iisObject = new-object System.DirectoryServices.DirectoryEntry("IIS://" + $server + "/w3svc/1/root")
	
	#get iis security property object
	$ipSec = $iisObject.Properties["IPSecurity"].Value
	
	#update binding flags to GetProperty
	$bindingFlags = [Reflection.BindingFlags] "Public, Instance, GetProperty"
	
	#get currently deny list
	$ipList = $ipSec.GetType().InvokeMember("IPDeny", $bindingFlags, $null, $ipSec, $null);
	
	#add to new ip list
	$ipArray += , $ipList
	
	#update binding flags to SetProperty
	$bindingFlags = [Reflection.BindingFlags] "Public, Instance, SetProperty"
	
	#update deny ip list
	$ipList = $ipSec.GetType().InvokeMember("IPDeny", $bindingFlags, $null, $ipSec, $ipArray);
	
	#set iis security property object
	$iisObject.Properties["IPSecurity"].Value = $ipSec
	
	#commit changes
	$iisObject.CommitChanges()
}

Open in new window


based on this post:
Using Powershell to Manipulate IP Restrictions on IIsWebVirtualDir
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question