12

I need to create a new self-signed IIS SSL certificate from a PowerShell script as part of an automated install.

Here's what I've tried:

Import-Module WebAdministation

New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https

New-SelfSignedCertificate -Subject Fluency -DnsName $computerName.$domainName -CertStoreLocation cert:\LocalMachine\My

Get-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "CN\=$Computername\.$DomainName" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443

Result

It says New-SelfSignedCertificate cannot be found for that line. If I create the certificate manually through the IIS manager, the rest of the code works fine.

Thanks for your help!

1

1 Answer 1

21

I got it to work this way

    Import-Module WebAdministration

    Set-Location IIS:\SslBindings

    New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https

    $c = New-SelfSignedCertificate -DnsName "myexample.com" -CertStoreLocation cert:\LocalMachine\My

    $c | New-Item 0.0.0.0!443
Sign up to request clarification or add additional context in comments.

1 Comment

For anyone coming across this solution you need to import the WebAdministration module first, so Import-Module WebAdministration followed by Set-Location IIS:\SslBindings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.