Created
December 19, 2025 00:38
-
-
Save TiloGit/fba621647ed7151df3f2019ed244c8a7 to your computer and use it in GitHub Desktop.
Create a cert to upload to Entra Enterprise App.
This file contains hidden or 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
| # ----------------------------- | |
| # 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