Import P12 Certificate

Heyyy… It’s been a while since i wrote a script, completely been busy with lots of other stuff. Anyways enough of my stuff lets get into the script and how this came as a request.

I had a colleague who asked me if i can get a cert deployed to wide range of workstations. I took this chance to write this quick script to deploy it via SCCM.

Import-Pfxcertificate -FilePath "Path of the Certificate" -Password "Password if required" -CertStoreLocation "Cert:\LocalMachine\Root"

The Script is very simple as you can see it requires 2 or 3 (if password is needed to import the Cert) Switches.

-FilePath = where the Cert is located easy way to get it. Locate the Cert and do a Shift + Right click and Copy as a path.
-Password = Some Certs will be password protected (Infact mostly on a Corp environment.) what is did instead of passing the test as it is i created a SecureString Variable as shown below. Which came in handy incase of changing the password for another cert while using the same Script.
-CertStoreLocation = This is where you want to place the Cert.

Click Here to see Microsoft’s Documentation – https://docs.microsoft.com/en-us/powershell/module/pki/import-pfxcertificate?view=windowsserver2019-ps

$pwd = 'Password' | convertto-securestring -asplainText -Force

This $Pwd Variable now can be used across the script rather than using the actual password everywhere in the script.

Published by iamfazul

Author of the site

Leave a comment