Skip to content

Instantly share code, notes, and snippets.

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 whereisaaron/d8b97e2f6cd52293db9c12baeba0b001 to your computer and use it in GitHub Desktop.
Save whereisaaron/d8b97e2f6cd52293db9c12baeba0b001 to your computer and use it in GitHub Desktop.
Export multiple Windows certificates to PFX files
#
# Must run in an Administrator shell to be able to export the keys
# Adjust the -Path, Where-Object clauses, and -FilePath to suit
#
$Password = Read-Host -Prompt "Enter password" -AsSecureString
Get-ChildItem -Path cert:\LocalMachine\My | Where-Object -Property FriendlyName -Like "Foo*" | Where-Object -Property Subject -Like "CN=www*" | ForEach-Object { Export-PfxCertificate -FilePath "$($_.FriendlyName) 2017-2018.pfx".Replace(" ","-").ToLower() -Cert $_ -ChainOption BuildChain -Password $Password }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment