Skip to content

Instantly share code, notes, and snippets.

@AaronSadlerUK
Created November 20, 2022 14:55
Show Gist options
  • Save AaronSadlerUK/521ae1718d52ad0ee13f50c5695541c5 to your computer and use it in GitHub Desktop.
Save AaronSadlerUK/521ae1718d52ad0ee13f50c5695541c5 to your computer and use it in GitHub Desktop.
Auto update WMSVC Certificate after Win-Acme runs
.\wacs.exe --installation script --script "Scripts\ImportWMSVC.ps1" --scriptparameters "'{CertThumbprint}'" --certificatestore My
param
(
[Parameter(Position=0,Mandatory=$true)]
[string]
$certThumbprint
)
#Use the new certificate
Stop-Service wmsvc
$strGuid = New-Guid
netsh http delete sslcert ipport=0.0.0.0:8172
netsh http add sslcert ipport=0.0.0.0:8172 certhash=$certThumbprint appid=`{$strGuid`} certstorename="MY"
#convert thumbprint to bytes and update registry
$bytes = for($i = 0; $i -lt $certThumbprint.Length; $i += 2) { [convert]::ToByte($certThumbprint.SubString($i, 2), 16) }
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\WebManagement\Server' -Name IPAddress -Value "*";
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\WebManagement\Server' -Name SslCertificateHash -Value $bytes
Start-Service wmsvc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment