Skip to content

Instantly share code, notes, and snippets.

@brockallen
Last active June 4, 2019 17:08
Show Gist options
  • Save brockallen/c11e4494a60303dd1c44754b978979c8 to your computer and use it in GitHub Desktop.
Save brockallen/c11e4494a60303dd1c44754b978979c8 to your computer and use it in GitHub Desktop.
#
# Generates a new cert in a .pfx file
#
param(
[Parameter(Mandatory = $true)]
$Name,
[Parameter(Mandatory = $true)]
$Password,
$Duration = 120
)
$password = ConvertTo-SecureString -Force -AsPlainText -String $Password
$cert = New-SelfSignedCertificate -DnsName $Name -NotAfter (Get-Date).AddMonths($Duration) -KeyLength 2048 -HashAlgorithm sha256 -CertStoreLocation Cert:\CurrentUser\My\
Export-Certificate -Cert $cert -FilePath .\$Name.cer
Export-PfxCertificate -Cert $cert -Password $password -FilePath .\$Name.pfx
Remove-Item "Cert:\CurrentUser\My\$($cert.Thumbprint)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment