Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ChrisTowles/9cf63fbba299f27d721c896adbc0dce5 to your computer and use it in GitHub Desktop.
Save ChrisTowles/9cf63fbba299f27d721c896adbc0dce5 to your computer and use it in GitHub Desktop.
For Local Development, to Create a Self Signed Cert and then add it to the Trusted Root Certifcations.
#Note : NOT FOR PRODUCTION USE. Development boxes only.
Import-Module PKI
$tempPath = "C:\Temp"
$certPath = "$tempPath\SelfSignedCert.cer"
$dnsName = '*.somedomain.com'
#Create Temp Folder
New-Item -ItemType Directory -Force -Path $tempPath
#Create Certificate
$SelfSignedCert = New-SelfSignedCertificate -DnsName $dnsName -CertStoreLocation cert:\LocalMachine\My
write-host "Self Signed Cert for $dnsName Created." -ForegroundColor DarkYellow
#Export Cert to File
Export-Certificate -Cert $SelfSignedCert -FilePath $certPath -Type CERT
write-host "Self Signed Cert for $dnsName Exported." -ForegroundColor DarkYellow
#Import Cert as Trusted Root Cert
Import-Certificate -FilePath $certPath -CertStoreLocation cert:\LocalMachine\root
#Check if its Installed.
$certInstalled = Get-ChildItem -Path Cert:\LocalMachine\root | where {$_.Thumbprint -eq $SelfSignedCert.Thumbprint}
if($certInstalled -ne $null)
{
write-host "Self Signed Cert for $dnsName Installed." -ForegroundColor DarkYellow
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment