Last active
August 4, 2021 11:23
-
-
Save gsmitheidw/60889b457a00ebf3fddd791fdab27282 to your computer and use it in GitHub Desktop.
Create Self Signed Cert in Powershell and add to trusted root cert store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
. Create Self Signed Cert and export for portability and import to trusted root certificate store | |
. | |
#> | |
$pwd = ConvertTo-SecureString -String (Read-Host -Prompt 'Enter Password' ) -Force -AsPlainText | |
$domain = Read-Host -Prompt 'Enter Domain (eg: contoso.com)' | |
$certpath = 'cert:\LocalMachine\My' | |
$CertDetails = @{ | |
Type = 'Custom' | |
Subject = $domain | |
KeyUsage = 'DigitalSignature' | |
KeyAlgorithm = 'RSA' | |
KeyLength = 2048 | |
CertStoreLocation = $certpath | |
NotAfter = (Get-Date).AddYears(5) | |
Confirm = $true | |
} | |
New-SelfSignedCertificate @CertDetails | |
$cert = Get-ChildItem -Path $certpath | where Subject -eq $domain | |
Export-PfxCertificate -FilePath $env:USERPROFILE\Desktop\msix-$domain.pfx -Password $pwd -Cert $cert -Confirm:$true | |
Import-PfxCertificate -FilePath $env:USERPROFILE\Desktop\msix-$domain.pfx -Password $pwd -CertStoreLocation Cert:\LocalMachine\Root -Confirm:$true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment