Importing a PFX into user store using powershell

This is a short post as someone asked me to give a sample for importing a pfx into user store using powershell:

 

$pfxcert = new-object system.security.cryptography.x509certificates.x509certificate2

$pfxcert.Import("pfxtest.pfx", "mypwd", [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"UserKeySet")

$store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "MY", CurrentUser

$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]"ReadWrite")

$store.Add($pfxcert)