【问题标题】:Issue when renewing IIS certificate in Powershell在 Powershell 中更新 IIS 证书时出现问题
【发布时间】:2019-05-01 12:27:14
【问题描述】:

我正在尝试通过 powershell 自动更新 IIS 中的证书,一切正常,除了脚本不会在不先删除现有证书的情况下覆盖现有证书。我想以优雅的方式做到这一点。这是导致问题的线路,有什么想法吗?

New-Item "IIS:\SslBindings\*!${Port}!${HostName}" -Thumbprint 
$NewCertThumbprint -SslFlags 1

这是错误:

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

(我使用指纹查询作为变量来区分新旧证书)。

【问题讨论】:

  • 复制项默认覆盖
  • 嗯,谢谢你,现在我收到一个新错误:“复制项:找不到与参数名称“指纹”匹配的参数。”
  • $CurrentCert = "‎E6760F37773D17FC5F3DDA192B5B82D738BCC3BE" $NewCert = "5F1C6318A7614DDEDAEFE6C81963426DD4611FDD" If ($CurrentCert -eq $NewCert) {Write-Host "Certificate El Thumbprints" 未更改。指纹不同,正在更新绑定。” Copy-Item "IIS:\SslBindings*!${Port}!${HostName}" -Thumbprint $NewCert -SslFlags 1 IISReset}
  • 不知道如何让 cmets 看起来更整洁。
  • 如果您需要这样做,只需编辑您的原始帖子。无论如何,我会事先使用 Remove-Item ,但也要检查这个先前的问题:stackoverflow.com/questions/22765648/…

标签: powershell ssl iis


【解决方案1】:

我会先测试一下,但这样的事情应该基于: iis-7-and-the-webadministration-snapin

这应该强制替换项目:

New-Item -Path "IIS:\Sites" -Name $HostName -Type Site -Bindings @{protocol="https";bindingInformation="*:$Port:";thumbprint=$NewCertThumbprint} -force

或者,您可以通过使用设置项来修改已经存在的内容来做同样的事情

Set-Item -Path "IIS:\Sites" -Name $HostName -Type Site -Bindings @{protocol="https";bindingInformation="*:$Port:";thumbprint=$NewCertThumbprint} -force

根据您的原始帖子,您应该能够在其末尾添加力量:

新项目“IIS:\SslBindings*!${Port}!${HostName}”-Thumbprint $NewCertThumbprint -SslFlags 1 -force

【讨论】:

    猜你喜欢
    • 2018-11-16
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 2020-09-18
    相关资源
    最近更新 更多