New-IISSiteBinding возвращает, что привязка уже существует, но привязка не существует в IIS.
Я пытаюсь импортировать привязки IIS из файла JSON в IIS с помощью PowerShell. Но всякий раз, когда я запускаю следующую команду:
New-IISSiteBinding -Name "IIS Site Name" -BindingInformation *:443:actualwebsite.com -CertificateThumbPrint *actualthumbprint* -CertStoreLocation My -Protocol https
Он возвращает:
New-IISSiteBinding : Web site binding '*:443:actualwebsite.com' already exists.
At line:1 char:1
+ New-IISSiteBinding -Name "IIS Site Name" -BindingInformation *:4 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-IISSiteBinding], ArgumentException
+ FullyQualifiedErrorId : InvalidArgument,Microsoft.IIS.Powershell.Commands.NewIISSiteBindingCommand
Когда я делаюRemove-IISSiteBinding
команда, там написано
WARNING: Web site binding 'https *:443:actualwebsite.com' does not exist.
Он также не отображается в консоли управления IIS, перезапуск IIS с помощью iisreset ничего не меняет. Когда я выполняю полный сценарий PowerShell, я получаю ошибки:
New-IISSiteBinding : Filename: \\?\C:\Windows\system32\inetsrv\config\applicationHost.config Error: Cannot commit configuration changes because the file has changed on disk
Полный сценарий PowerShell:
$backupfilepath = "C:\Backup\IISBindings.json"
$Sites = Get-Content -Raw $backupfilepath | ConvertFrom-Json
$Sites | ForEach-Object {
$siteName = $_.Site;
$_.Bindings | ForEach-Object {
$certStoreName = "Cert:\LocalMachine\" + $_.CertificateStoreName;
$bindingInformation = $_.BindingInformation
$certificateHash = $_.CertificateHash
if (-not ([string]::IsNullOrEmpty($certificateHash))) {
if ($null -ne (get-iissitebinding -Name $siteName | Where-Object { $_.bindinginformation -eq $bindingInformation })) {
Write-Host "This is a current binding, removing existing"
Remove-IISSiteBinding -Name $siteName -Protocol https -BindingInformation $bindingInformation
Write-Host "Creating a new binding"
New-IISSiteBinding -Name $siteName -BindingInformation $bindingInformation -CertificateThumbPrint $certificateHash -CertStoreLocation $certStoreName -Protocol https -Force
}
else {
Write-Host "This is not a current binding"
New-IISSiteBinding -Name $siteName -BindingInformation $bindingInformation -CertificateThumbPrint $certificateHash -CertStoreLocation $certStoreName -Protocol https -Force
}
}
else {
if ($null -ne (get-iissitebinding -Name $siteName | Where-Object { $_.bindinginformation -eq $bindingInformation })) {
Write-Host "This is a current binding, removing existing"
Remove-IISSiteBinding -Name $siteName -Protocol http -BindingInformation $bindingInformation
Write-Host "Creating a new binding"
New-IISSiteBinding -Name $siteName -BindingInformation $bindingInformation -Protocol http -Force
}
else {
Write-Host "This is not a current binding"
New-IISSiteBinding -Name $siteName -BindingInformation $bindingInformation -Protocol http -Force
}
}
}
}
Как мне это решить?