首页 > 解决方案 > 尝试将绑定添加到 IIS 站点时,我返回:“配置对象是只读的”

问题描述

我已将我的 Powershell 脚本放在下面。我正在从自签名证书 ($ca) 创建一个 HTTPS 证书 ($httpsk)。当我运行脚本时,它在“New-IISSiteBinding”上失败。总的来说,这应该是创建 2 个证书(检查),然后使用其中一个证书

$ca = New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My `
    -FriendlyName $Name -DnsName $Name `
    -KeyusageProperty All -KeyUsage CertSign, CRLSign, DigitalSignature `
    -KeyAlgorithm RSA -KeyLength 4096 -NotAfter (Get-Date).AddYears(20)

# Generate HTTPS certificate issued by the self-signed CA
$httpsk = New-SelfSignedCertificate -CertStoreLocation cert:\LocalMachine\My `
    -FriendlyName "$FriendlyNameHTTPS" `
    -DnsName $DnsNameHTTPS `
    -KeyAlgorithm RSA -KeyLength 2048 -Signer $ca -NotAfter (Get-Date).AddYears(3)
Write-Warning "Generated a certificate which may be used for the HTTPS binding."


Export-Certificate -FilePath "C:\temp\certificate" -Cert $ca | Out-Null

$thumbprint = $httpsk.thumbprint
$websiteName = "Default Web Site"

New-IISSiteBinding -Name $websiteName -BindingInformation "*:443:$domainName" -CertificateThumbPrint $thumbprint -CertStoreLocation "cert:\LocalMachine\my"  -Protocol "https"

我得到的错误是:

New-IISSiteBinding : The configuration object is read only, because it has been committed by a call to ServerManager.CommitChanges(). If
write access is required, use ServerManager to get a new reference.
At line:1 char:5
+     New-IISSiteBinding -Name $websiteName -BindingInformation "*:443" ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-IISSiteBinding], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.IIS.Powershell.Commands.NewIISSiteBindingCommand

我查看了堆栈溢出、Microsoft 和几个第三方站点,但找不到任何关于此的内容。有类似的东西可能对您有所帮助。它的问题略有不同,它是 C# 而不是 PowerShell 脚本。这是链接。究竟是什么问题,我该如何解决?我是 IIS 的半新手。当它说“配置对象”时,它指的是什么?是证书、站点还是绑定?

标签: powershelliisbinding

解决方案


您可以根据本网站检查您的命令格式错误是否导致问题。

这是供参考:New-IISSiteBinding


推荐阅读