rj07thomas

Create a pfx certificate file with PowerShell

Oct 19th, 2023
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. Clear-Host
  2. [string]$certDetailsString
  3.  
  4.  
  5. $choosePassword = Read-Host "Please enter a password"
  6. $myPwd = ConvertTo-SecureString -String $choosePassword -Force -AsPlainText
  7.  
  8. Get-ChildItem -Path Cert:\LocalMachine\My
  9.  
  10. $myCert = Read-Host "Please paste a thumbprint"
  11. $certDetails = Get-ChildItem -Path Cert:\LocalMachine\My\$myCert
  12.  
  13. $certDetailsString = $certDetails.Subject
  14. $subject = $certDetailsString.Split('=')
  15.  
  16. Clear-Host
  17.  
  18. $subjectOne = $subject[1]
  19. $subjectOneDetails = $subjectOne.Split('.')
  20.  
  21. $subjectOneNetBIOS = $subjectOneDetails[0]
  22. $subjectOneNetBIOS
  23.  
  24. $outputFile = ".\pfxFiles\"+$subjectOneNetBIOS+".pfx"
  25. $outputFile
  26. Export-PfxCertificate -Cert $certDetails -FilePath "$outputFile" -Password $mypwd
Advertisement
Add Comment
Please, Sign In to add comment