Skip to content

Instantly share code, notes, and snippets.

@TiloGit
Created December 19, 2025 00:38
Show Gist options
  • Select an option

  • Save TiloGit/fba621647ed7151df3f2019ed244c8a7 to your computer and use it in GitHub Desktop.

Select an option

Save TiloGit/fba621647ed7151df3f2019ed244c8a7 to your computer and use it in GitHub Desktop.
Create a cert to upload to Entra Enterprise App.
# -----------------------------
# VARIABLES
# -----------------------------
$myName = "myAppCert48"
$certName = "CN=$myName"
$certValidity = 48 # months
$certPath = "Cert:\CurrentUser\My"
$pfxOutput = "C:\temp\$myName.pfx"
$cerOutput = "C:\temp\$myName.cer"
$pfxPassword = Read-Host "Enter PFX password" -AsSecureString
# -----------------------------
# CREATE SELF-SIGNED CERT
# -----------------------------
$cert = New-SelfSignedCertificate `
-Subject $certName `
-CertStoreLocation $certPath `
-KeyExportPolicy Exportable `
-KeySpec Signature `
-KeyLength 2048 `
-Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" `
-NotAfter (Get-Date).AddMonths($certValidity)
Write-Host "Certificate created with Thumbprint: $($cert.Thumbprint)"
# -----------------------------
# EXPORT PFX (private key)
# -----------------------------
Export-PfxCertificate `
-Cert $cert `
-FilePath $pfxOutput `
-Password $pfxPassword
# -----------------------------
# EXPORT CER (public key)
# -----------------------------
Export-Certificate `
-Cert $cert `
-FilePath $cerOutput
Write-Host "Export complete:"
Write-Host " PFX: $pfxOutput"
Write-Host " CER: $cerOutput"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment