Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create self signed iis ssl certificate from powershell

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!

like image 386
Robert Bratton Avatar asked Feb 05 '14 17:02

Robert Bratton


People also ask

How do I create a self-signed certificate in IIS using PowerShell?

To create a self-signed certificate with PowerShell, we need to use the New-SelfSignedCertificate command. When you create a self-signed certificate manually, you need to give few properties like DNSName, FriendlyName, Certificate start date, expiry date, Subject, a path of the certificate.

How do you create self signed SSL in IIS?

In IIS Manager, do the following to create a self-signed certificate: In the Connections pane, select your server in the tree view and double-click Server Certificates. In the Actions pane, click Create Self-Signed Certificate. Enter a user-friendly name for the new certificate and click OK.

How do I bind a certificate in IIS using PowerShell?

To enable SSL three steps are involved: Acquiring and installing a certificate. Creating an SSL binding in IIS. Assigning the certificate to the IP:Port of the IIS binding.


1 Answers

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
like image 88
Avner Avatar answered Oct 19 '22 01:10

Avner