Home
> Uncategorized > Transfer #IIS bindings from one server to another using #Powershell
Transfer #IIS bindings from one server to another using #Powershell
Ok, it’s a common task, you’re migrating from one server to another, but you have one website that responds to 100’s of bindings, and you have to move them. Of course you can copy and paste one by one, but here’s a script to do so. It also works with IDN domains.
First, on the source server, run this;
Import-Module WebAdministration
$siteName = "YOUR_SITE.COM"
$exportPath = "C:\TEMP\bindings.csv"
$bindings = Get-WebBinding -Name $siteName |
Where-Object { $_.protocol -eq 'http' } |
Select-Object protocol, bindingInformation
$bindings | Export-Csv -Path $exportPath -NoTypeInformation -Encoding UTF8
Then, copy the file bindings.csv to the new server, and import them using this
Import-Module WebAdministration
$siteName = "YOUR_SITE.com"
$importPath = "C:\temp\bindings.csv"
$bindings = Import-Csv -Path $importPath -Encoding UTF8
foreach ($binding in $bindings) {
$protocol = $binding.protocol
$bindingInformation = $binding.bindingInformation -split ':'
$ipAddress = $bindingInformation[0]
$port = $bindingInformation[1]
$hostHeader = $bindingInformation[2]
New-WebBinding -Name $siteName -Protocol $protocol -IPAddress $ipAddress -Port $port -HostHeader $hostHeader
}
This doesn’t work for HTTPS domains, since you need to copy the public/private keys as well, and it’s more complex.
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback