Last active
June 4, 2019 17:08
-
-
Save brockallen/c11e4494a60303dd1c44754b978979c8 to your computer and use it in GitHub Desktop.
This file contains 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
# | |
# 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