Skip to content

Instantly share code, notes, and snippets.

Created January 3, 2019 01:17
What would you like to do?
Create a new self-signed cert with export key
# Create self-signed certificate and export pfx and cer files
$PfxFilePath = 'KVWebApp.pfx'
$CerFilePath = 'C:\Users\<name>\Documents\learn\key vault\blog\KVWebApp.cer'
$DNSName = ''
$Password = 'MyPassword"'
$StoreLocation = 'CurrentUser' # be aware that LocalMachine requires elevated privileges
$CertBeginDate = Get-Date
$CertExpiryDate = $CertBeginDate.AddYears(1)
$SecStringPw = ConvertTo-SecureString -String $Password -Force -AsPlainText
$Cert = New-SelfSignedCertificate -DnsName $DNSName -CertStoreLocation "cert:\$StoreLocation\My" -NotBefore $CertBeginDate -NotAfter $CertExpiryDate -KeySpec Signature
Export-PfxCertificate -cert $Cert -FilePath $PFXFilePath -Password $SecStringPw
Export-Certificate -cert $Cert -FilePath $CerFilePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment