Hello All -
I just spent a very long time studying the various documentation for scripting SSL certs for WMSVC (Web Deploy). There were some gotcha's in Windows 10 that required some details. I thought I'd contribute my code here so that others working with certs and IIS 10 will lose less hair than I did. :)
The reason I have this script is to update the SSL cert used when building out VM's from a template. Obviously once the host is newly named, you will have to create a new Self signed cert for it so you can deploy using MS Deploy.
First, I have a simple command file wrapper around the powershell which sets up the fully qualified hostname and makes it easier to call from the RunOnce registry. You will probably need to munge this to fit your own environment.
set FQHN=%COMPUTERNAME%.<yourdomain> cd C:\WMSVCCONFIG powershell -ExecutionPolicy bypass -NonInteractive -NoProfile -command .\createNew.ps1 > createNew_log.txt 2>&1
And now the powershell:
$FQHN = "$env:FQHN"; Import-Module WebAdministration "Attempting to stop WMSVC..." net stop WMSVC"Removing unassigned addresses SSl bindings... (ignore errors)" Remove-Item -Path IIS:\SslBindings\0.0.0.0!8172"Creating new cert..."$webServerCert = New-SelfSignedCertificate -Type Custom -DnsName $FQHN -Subject "CN=$FQHN" -KeySpec "Signature" -KeyUsage @("KeyEncipherment","DataEncipherment") -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1") -TestRoot -FriendlyName "$FQHN Self-Signed For MSDEPLOY Agent" -NotAfter $([datetime]::now.AddYears(5)) -CertStoreLocation Cert:\LocalMachine\My$thumbprint = $webServerCert.Thumbprint"Creating new bindings with new cert with hash: " + $thumbprint; # Note: the exact appid is required for WMSVC to actually start in IIS 10.0. # Also note you have to supply certstorename=My explicitly because there is a defect # in some version of Server 2016 which doesn't set the binding store name by default. # Without it, WMSVC just won't start. netsh http add sslcert ipport="0.0.0.0:8172" appid='{d7d72267-fcf9-4424-9eec-7e1d8dcec9a9}' certhash=$thumbprint certstorename=My"Attempting start of WMSVC..." net start WMSVC