0

I have put my Powershell Script below. I am creating an HTTPS certificate ($httpsk) from a self-signed certificate ($ca). When I run the script, It fails on the "New-IISSiteBinding." Overall, this should be creating 2 certificates (check) and then using one of those certificates

$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"

The error I get is:

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

I looked around stack overflow, Microsoft, and several third party sites but cannot find anything on this. There was something similar that might be helpful for you to look at. It's with a slightly different problem and it was C# rather than a PowerShell script. Here is the link. What exactly is the problem and how do I fix it? I'm semi-new to IIS. What is it referring to when it says the "configuration object"? is that the certificate, the site, or the binding?

William
  • 62
  • 1
  • 8

1 Answers1

0

You can check whether your command format error is causing the problem according to this website.

This is for reference: New-IISSiteBinding

Theobald Du
  • 824
  • 4
  • 7
  • Yeah, I was all over that site already. I guess I could try specifying an IP rather than using a wildcard in ```binding information```, but that doesn't seem like it would fix my problem. Not sure what else is incorrect in the format. – William Jun 23 '21 at 12:46
  • You can refer to: https://stackoverflow.com/questions/25384049/resolve-configuration-object-is-read-only-because-it-has-been-committed-by-a-c – Theobald Du Jul 15 '21 at 07:39
  • Hey thanks for the response again. I fixed it, the problem was that since I was testing it alot, for some reason when I deleted a site to recreate it, it didn't fully delete and something was still there. I could not see it in any file systems or in IIS however. A simple restart of my PC fixed it. I think it was stuck in some buffer somewhere – William Jul 16 '21 at 14:04