#* FileName: ImportPFXCert.ps1 #*============================================================================= #* Script Name: [Import PFX] #* Created: 06 Jan 2014 #* Author: #* Reqrmnts: #* Keywords: #*============================================================================= #* Purpose: Import PFX certificate #* #* #*============================================================================= #*============================================================================= #* REVISION HISTORY #*============================================================================= #* Date: [DATE_MDY] #* Time: [TIME] #* Issue: #* Solution: #* #*============================================================================= #*============================================================================= #* FUNCTION LISTINGS #*============================================================================= # Function: Import-PfxCertificate # Created: 06 Jan 2018 # Author: # Arguments: # ============================================================================= # Purpose: Imports the PFX Certificate # # # ============================================================================= function Import-PfxCertificate { param([String]$certPath,[String]$certRootStore = "CurrentUser",[String]$certStore = "My",$pfxPass = $null) $pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 if ($pfxPass -eq $null) {$pfxPass = read-host "Enter the pfx password" -assecurestring} $pfx.import($certPath,$pfxPass,"Exportable,PersistKeySet") $store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore) $store.open("MaxAllowed") $store.add($pfx) $store.close() } #*============================================================================= #* SCRIPT BODY #*============================================================================= #Remove expiring Certificate based on Certificate thumbprint #Remove-Item -Path cert:\CurrentUser\My\FC57927E384EF635DE32876A1B83ADB6D1B10FCA # Call the "Import-PfxCertificate" function. Import-PfxCertificate "\\server\share\DigitalCerts\Certificate.pfx" "CurrentUser" "My" "" #*============================================================================= #* END OF SCRIPT: [Import PFX] #*=============================================================================