Import-PfxCertificate

Imports certificates and private keys from a Personal Information Exchange (PFX) file to the destination store.

Syntax

Default (Default)

Import-PfxCertificate
    [-Exportable]
    [-Password <SecureString>]
    [[-CertStoreLocation] <String>]
    [-FilePath] <String>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

The Import-PfxCertificate cmdlet imports certificates and private keys from a PFX file to the destination store. Certificates with and without private keys in the PFX file are imported, along with any external properties that are present.

Delegation may be required when using this cmdlet with Windows PowerShell remoting and changing user configuration.

Examples

EXAMPLE 1

$mypwd = Get-Credential -UserName 'Enter password below' -Message 'Enter password below'

$params = @{
    FilePath = 'C:\mypfx.pfx'
    CertStoreLocation = 'Cert:\LocalMachine\My'
    Password = $mypwd.Password
}
Import-PfxCertificate @params

This example imports the PFX file mypfx.pfx with a private, non-exportable key into the My store for the machine account.

EXAMPLE 2

Get-ChildItem -Path C:\mypfx.pfx |
    Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -Exportable

This example imports the PFX file mypfx.pfx with a private, exportable key into the My store for the current user. The Password parameter is not required since this PFX file is not password protected.

EXAMPLE 3

Set-Location -Path Cert:\LocalMachine\My

Import-PfxCertificate -FilePath C:\mypfx.pfx

This example imports the PFX file mypfx.pfx into the My store for the machine account. The Password parameter is not required since this PFX file is protected using the ___domain account of this machine. This requires a Windows Server 2012 or later ___domain controller.

Parameters

-CertStoreLocation

Specifies the path of the store to which certificates will be imported. If this parameter is not specified, then the current path is used as the destination store.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:1
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Exportable

Specifies whether the imported private key can be exported. If this parameter is not specified, then the private key cannot be exported.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-FilePath

Specifies the path for the PFX file.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:FullName

Parameter sets

(All)
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Password

Specifies the password for the imported PFX file in the form of a secure string.

Parameter properties

Type:System.SecureString
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

String

A String containing the path to the PFX file.

Outputs

X509Certificate2

The imported X509Certificate2 object contained in the PFX file that is associated with private keys.