Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Powershell中续订IIS证书时出现问题_Powershell_Ssl_Iis - Fatal编程技术网

在Powershell中续订IIS证书时出现问题

在Powershell中续订IIS证书时出现问题,powershell,ssl,iis,Powershell,Ssl,Iis,我正在尝试通过powershell自动更新IIS中的证书,这一切都很顺利,只是脚本不会覆盖现有证书,除非先删除它。我想以优雅的方式做这件事。这是引起问题的线索,有什么想法吗 New-Item "IIS:\SslBindings\*!${Port}!${HostName}" -Thumbprint $NewCertThumbprint -SslFlags 1 下面是错误: New-Item : Cannot create a file when that file already exists

我正在尝试通过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

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

我会先测试是否有效,但类似的测试应该基于:

这将强制更换以下项目:

新项目-路径“IIS:\Sites”-名称$HostName-类型Site-Bindings@{protocol=“https”;bindingInformation=“*:$Port:”;thumbprint=$NewCertThumbprint}-force

或者,您也可以通过使用set项修改已经存在的内容来执行相同的操作

设置项-路径“IIS:\Sites”-名称$HostName-类型Site-Bindings@{protocol=“https”;bindingInformation=“*:$Port:”;thumbprint=$NewCertThumbprint}-force

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

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

Copy Item被defaultHmmm覆盖,谢谢,现在我得到一个新错误:“Copy Item:找不到与参数名称'Thumbprint'匹配的参数”。$CurrentCert=”‎E6760F37773D17FC5F3DDA192B5B82D738BC3BE“$NewCert=$5F1C6318A7614DDAEFE6C81963426DD4611FDD”如果($CurrentCert-eq$NewCert){Write Host“证书指纹匹配,绑定不变。”}否则{Write Host”指纹不同,正在更新绑定。“复制项”IIS:\SslBindings*!${Port}!${HostName}”-Thumbprint$NewCert-SslFlags 1 IISReset}不知道如何让评论看起来更整洁。如果需要,只需编辑原始帖子即可。无论如何,我会事先使用Remove Item,但也会检查前面的问题: