Hello. I'm writing a PowerShell script to automate the deployment new web services and sites. At this point, I have everything sorted out except assigning an SSL certificate to the site(s). I've searched everywhere and found only two examples, neither of which appear to assign the certificate.
I've been beating my head against a wall for a week on this, so I would greatly appreciate any assistance.
Here is the line that appears to work as expected. I can "write-host $certificate.Thumbprint", and it returns the correct thumbprint, and only the thumbprint.
$certificate = Get-ChildItem cert:\LocalMachine\MY | Where-Object {$_.Subject -match "CN=VM*"} | Select-Object -First 1
Here are the things I've tried for what I think is the final step, to assign the certificate to the site, none of which are currently working.
1. Get-Item cert:\LocalMachine\My\$certificate.Thumbprint | New-ItemProperty IIS:\Sites\$webServiceName 0.0.0.0!443
i. #this completes without error, but doesn't assign the certificate
2. Get-Item cert:\LocalMachine\My\$certificate.Thumbprint | New-Item 0.0.0.0!443
i. #this also completes without error, but doesn't assign the certificate
3. netsh http add sslcert ipport=0.0.0.0:443 certstore=MY certhash=$certificate.Thumbprint appid={}
i. #this throws an invalid appid error. I've tried assigning a random appid, which also fails. I don't know how to get the appid of a particular IIS 7.5 site, and I'm not sure this would work even if I entered a valid appid.
Thanks, in advance, for your help.