I'm trying to automate the renewal of certificates in IIS via powershell, which is all going fine, except that the script won't overwrite the existing cert without removing it first. I want to do it in a graceful fashion. Here's the line that's causing the issue, any ideas?
New-Item "IIS:\SslBindings\*!${Port}!${HostName}" -Thumbprint
$NewCertThumbprint -SslFlags 1
And here's the error:
New-Item : Cannot create a file when that file already exists
At C:\Scripts\SSL_Check.ps1:20 (the line above) char:13
+ New-Item "IIS:\SslBindings\*!${Port}!${HostName}" -Thumbprint $NewCe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-Item], Win32Exception
+ FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.NewItemCommand
(I've used thumbprint queries as variables to differentiate between the old and new certs).