Reputation: 11
I'm hosting about 100 sites in IIS. I'm moving to a new ip range. While I've added the new ip addresses manually ( it took some time) I would like to avoid removing the old ip's manually. I have already removed the old ip's from the network. Is there a powershell command that would allow me to remove bindings for all sites containing a specific ip address?
Upvotes: 1
Views: 3256
Reputation: 10107
You have a list of IP addresses and you would like to remove each one from bindings in IIS? If so, put the list of IP address(one per line) in a text file, ie. IPs.txt, open powershell, cd to the directory where IPs.txt sits and run the following:
Import-Module WebAdministration
cat .\IPs.txt | % { Get-WebBinding -IPAddress $_ | Remove-WebBinding -Confirm:$true}
You will have to confirm each delete but this is most likely preferable to deleting an incorrect binding, ie. if you have an empty line line in the file it will return ALL bindings..
Upvotes: 1
Reputation: 23
I would look at using the Web Server (IIS) Administration Cmdlets in Windows PowerShell
There's some awesome functionality available for doing what you're after.
Example:
Get-WebBinding -IPAddress "192.168.*" | Remove-WebBinding -WhatIf
This example selects all web bindings on the local machine that matches the ip address (including wildcard) then pipes the results to the Remove-WebBinding cmdlet. Obviously you'd need to set the criteria up for your own scenario. Remove the -WhatIf switch only when you're sure you've selected the bindings you're interested in and are ready to do it (!)
You may have been able to have used the Set-WebBinding command that also exists in this module to just update the original ones.
Hope that helped.
Upvotes: 0