title: How do I set the IIS 10.0 Management Service SSL Certificate via a Powershell script to allow Web Deploy?
body: <p>When I run windows updates and sysprep my Amazon EC2 instance (Windows Server 2016), I have to create a new self-signed certificate. I can then select the SSL certificate (I named it WebDeploy) in the Management Service screen. I have figured out how to create the SSL certificate from Windows Powershell, but I have to select the SSL Certificate from the dropdown in the screenshot. How can I set that SSL certificate from a command line?</p>
  
  <p><a href="https://i.stack.imgur.com/lf0nH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lf0nH.png" alt="IIS Management Service screenshot"></a></p>
  
  <p>Here's what I tried that did not work - I was able to avoid errors, but none of them allowed the WebDeploy to work without me going into the IIS Manager screen and manually selecting the dropdown.</p>
  
  <pre><code>Stop-Service wmsvc
  $strGuid = New-Guid
  Import-Module WebAdministration
  Remove-Item -Path IIS:\SslBindings\0.0.0.0!8172
  Get-Item -Path  "cert:\localmachine\my\$strHashThumbprint" | New-Item -Path 
  IIS:\SslBindings\0.0.0.0!8172 
  Start-Service wmsvc
  </code></pre>
  
  <p>And also, this didn't work:</p>
  
  <pre><code>Stop-Service wmsvc
  netsh http delete sslcert ipport=0.0.0.0:8172
  netsh http add sslcert ipport=0.0.0.0:8172 certhash=$strHashThumbprint appid=`{$strGuid`} certstorename="MY" sslctlstorename="MY"
  Start-Service wmsvc
  </code></pre>
  
  <p>And finally, this didn't work:</p>
  
  <pre><code>Stop-Service wmsvc
  Add-NetIPHttpsCertBinding -IpPort "0.0.0.0:8172" -CertificateHash $strHash -CertificateStoreName "My" -ApplicationId "{$strGuid}" -NullEncryption $false 
  Start-Service wmsvc
  </code></pre>