-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiis-site-migration.ps1
24 lines (18 loc) · 1.06 KB
/
iis-site-migration.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Define variables
$domainName = "example.com"
$oldSiteName = "SiteA"
$newSiteName = "SiteB"
$certificateThumbprint = "1234567890abcdef"
# Get the IIS Manager module
Import-Module WebAdministration
# Get the current binding information for the domain name
$binding = Get-WebBinding -Name $oldSiteName -Protocol "https" | Where-Object {$_.bindingInformation -like "*:$domainName"}
# Get the certificate associated with the binding
$certificate = Get-Item -Path "Cert:\LocalMachine\My\$certificateThumbprint"
# Create a new binding for the new site with the same binding information
$bindingInformation = $binding.bindingInformation
$newBinding = New-WebBinding -Name $newSiteName -Protocol "https" -HostHeader $domainName -SslFlags 1 -CertificateThumbprint $certificate.Thumbprint -IPAddress "*" -Port $bindingInformation.Split(":")[-1]
# Remove the old binding from the old site
Remove-WebBinding -Name $oldSiteName -BindingInformation $bindingInformation
# Add the new binding to the new site
Add-WebBinding -Name $newSiteName -BindingInformation $newBinding.bindingInformation