Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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
&引用;IIS:当文件已存在时,无法创建该文件。异常。消息";通过SSL证书和powershell创建https绑定时_Powershell_Security_Ssl_Https_Ssl Certificate - Fatal编程技术网

&引用;IIS:当文件已存在时,无法创建该文件。异常。消息";通过SSL证书和powershell创建https绑定时

&引用;IIS:当文件已存在时,无法创建该文件。异常。消息";通过SSL证书和powershell创建https绑定时,powershell,security,ssl,https,ssl-certificate,Powershell,Security,Ssl,Https,Ssl Certificate,我编写此方法是为了使用已安装的SSL证书并在IIS中启用https绑定。但当我调用此方法时,我发现Powershell中的错误 IIS: Cannot create a file when that file already exists.Exception.Message 这是启用绑定的函数。我从.json文件中读取的所有必需变量 function IIS-SSL-SETUP { $Global:iisStatus = $started try {

我编写此方法是为了使用已安装的SSL证书并在IIS中启用https绑定。但当我调用此方法时,我发现Powershell中的错误

IIS: Cannot create a file when that file already exists.Exception.Message
这是启用绑定的函数。我从.json文件中读取的所有必需变量

function IIS-SSL-SETUP {
    
    $Global:iisStatus = $started
    try {
        $pwd = ConvertTo-SecureString -String $PFX_PASSWORD -Force -AsPlainText
        Import-PfxCertificate -FilePath $PFX_FILE_LOCATION Cert:\LocalMachine\My -Password $pwd
        $pfx.import($PFX_FILE_LOCATION, $PFX_PASSWORD, "Exportable,PersistKeySet") 
        $store = new-object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreName]::Root, "localmachine")
        $store.open("MaxAllowed") 
        $store.add($pfx) 
        $store.close()
        Import-Module WebAdministration
        Set-Location IIS:\
        if ($null -eq (Get-WebBinding "MyServer" | Where-Object { $_.bindingInformation -eq "*:$($IIS_SSS_HTTPS_PORT):" })) {
            New-WebBinding -Name "MyServer" -IP "*" -Port $IIS_SSS_HTTPS_PORT -Protocol https
            Get-WebBinding -Port $IIS_SSS_HTTP_PORT -Name "MyServer" | Remove-WebBinding
            cd SslBindings
            dir
            $pfx.Import($PFX_FILE_LOCATION, $PFX_PASSWORD, 'DefaultKeySet')
            $certThumbprint = "\LocalMachine\My\$($pfx.Thumbprint)"
            get-item Cert:$certThumbprint | new-item 0.0.0.0!$($IIS_SSS_HTTPS_PORT) //I am getting this error at this line
            $Global:iisStatus = "Passed"
        }
        else {
            $Global:iisStatus = "Failed"
            $Global:iisMsg = "Port $($IIS_SSS_HTTPS_PORT) is already in use, please mention some different port number in sslConfig.json."
            $Global:iisMsgColor = "Yellow"
        }
    }
    catch {
        $Global:iisStatus = "Failed"
        $Global:iisMsgColor = "Red"
        $Global:iisMsg = "IIS: $_.Exception.Message"
    }
}

@Mehul Parmar,如你所问,我已删除我的评论,并将其移动到一个答案中:

dir
命令是否列出了一些内容?在你的情况下可能应该这样。我的测试没有结果,工作正常,没有错误。您可以测试元素是否已存在:

if(-not(测试路径0.0.0.0!$($IIS\U SSS\U HTTPS\U端口))

“MyServer”
是一个奇怪的网站名称,别忘了绑定是绑定到网站而不是服务器的。还有一件事:
Get WebBinding-Port$IIS\u SSS\u HTTP\u Port-Name“MyServer”| Remove WebBinding
将在未定义
$IIS\u SSS\u HTTP\u Port
的情况下删除所有绑定。也许你更喜欢这个:


获取WebBinding-protocolhttp-Name“MyServer”|删除WebBinding

噢,该死!我正在创建新绑定,然后删除所有绑定,因为未定义
IIS\u SSS\u HTTP\u端口
。非常感谢@CFou。这解决了我的问题。@cf您好,您可以将您的评论作为答案发布吗