Script to rebind an IIS site to a new IP and a new SSL cert – PowerShell

Here is a script that I used during a DR failover test. We would failover a web server to a DR side,rename it, re-ip it, rebind the SSL certs. During this process it would loose the binding as the old IP’s no longer existed.

The script does the following:
-It removes the current IP and SSL biding for a site in IIS
-It Binds the existing sites to their new IPs for port 443 and 80
-It Binds an SSL cert to the new site, see SSL friendly cert names by running this PowerShell commands “Get-ChildItem Cert:\LocalMachine\My”

Import-Module WebAdministration

#Remove the default Binding
Remove-WebBinding -Name "Site1" -BindingInformation "*:443:"
Remove-WebBinding -Name "Site1" -BindingInformation "*:80:"
Remove-WebBinding -Name "Site2" -BindingInformation "*:443:"
Remove-WebBinding -Name "Site2" -BindingInformation "*:80:"

#Bind an IIS web site to an IP
New-WebBinding -Name "Site1" -Protocol "https" -Port 443 -IPAddress 192.168.11.13
New-WebBinding -Name "Site1" -Protocol "http" -Port 80 -IPAddress 192.168.11.13
New-WebBinding -Name "Site2" -Protocol "https" -Port 443 -IPAddress 192.168.11.12
New-WebBinding -Name "Site2" -Protocol "http" -Port 80 -IPAddress 192.168.11.12

#Bind an IIS web site to an SSL certificate
$certificate = Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.FriendlyName -eq "CRT_Site1"}
New-Item -Path "IIS:\SslBindings\192.168.11.13!443" -Value $certificate
$certificate = Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.FriendlyName -eq "CRT_Site2"}
New-Item -Path "IIS:\SslBindings\192.168.11.12!443" -Value $certificate
This entry was posted in Microsoft, Scripting and tagged , , , , . Bookmark the permalink.

Leave a Reply

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