Nov 5, 2025

PowerShell Script to Create and Bind a Self-Signed SSL Certificate

The script creates a new self-signed certificate, generates a unique App ID, and binds it to port 5555 — automatically.

Copy and run this in PowerShell (Run as Administrator):

# Get computer hostname
$hostname = hostname
Write-Host "Hostname: $hostname"

# Create a self-signed cert for localhost + hostname (valid 1 year)
$cert = New-SelfSignedCertificate -DnsName "localhost", $hostname `
  -CertStoreLocation "Cert:\LocalMachine\My" `
  -NotAfter (Get-Date).AddYears(1)
$thumb = $cert.Thumbprint
Write-Host "Cert Thumbprint: $thumb"

# Create new Application ID (GUID)
$appid = "{" + ([guid]::NewGuid().ToString()) + "}"
Write-Host "App ID: $appid"

# Bind certificate to all interfaces on port 5555
$ipport = "0.0.0.0:5555"
netsh http add sslcert ipport=$ipport certhash=$thumb appid=$appid

Write-Host "✅ Done! SSL binding created on port 5555."

🔍 Why This Helps

When hosting a local web API or service (e.g., on Kestrel or IIS Express), HTTPS often fails due to:

This script fixes all of it in one run — clean, fast, repeatable.


🧹 Optional: Clean Old Bindings

If you want to clear any previous SSL settings before running the script:

netsh http delete sslcert ipport=0.0.0.0:5555
netsh http delete sslcert ipport=localhost:5555
netsh http delete sslcert ipport=192.168.1.25:5555

Ignore “file not found” messages — that just means no old bindings exist.


✅ Verify

After running the script, check:

netsh http show sslcert

You should see your new certificate bound to port 5555.

0 comments: