Skip to content

Instantly share code, notes, and snippets.

@bachoang
Created January 3, 2019 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bachoang/e5f4671e35a97f3b3e8a579b9a2c05b9 to your computer and use it in GitHub Desktop.
Save bachoang/e5f4671e35a97f3b3e8a579b9a2c05b9 to your computer and use it in GitHub Desktop.
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 = 'MyComputer.Contoso.com'
$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