< Back
Import-PSCredential
Post
NAME Import-PSCredential
SYNOPSIS
Retrieves and decrypts an exported PowerShell Credential from file or Azure KeyVault back into a PSCredential
object.
SYNTAX
Import-PSCredential [-Path] <String> -Thumbprint <String> [-CertificateStore <String>] [<CommonParameters>]
Import-PSCredential [-Path] <String> -SecureKey <SecureString> [<CommonParameters>]
Import-PSCredential -KeyVault <String> -SecretName <String> [<CommonParameters>]
DESCRIPTION
Import-PSCredential is used to retrieve a previously saved PowerShell Credential object from disk
or from Azure KeyVault and returns a PowerShell Credential object [System.Management.Automation.PSCredential] that
can be used within scripts and
Desired State Configurations. When retrieving from disk, the method used to encrypt the credential must be used to
decrypt the credential.
PARAMETERS
-Path <String>
Path to the JSON file that contains the encrypted credential.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-SecureKey <SecureString>
The SecureString that was used as a Pre-Shared-Key for encrypting the credential password.
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Thumbprint <String>
The Thumbprint of the certificate on the local computer that contains the private key of the certificate used
to encrypt the credential password.
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-CertificateStore <String>
Specifies the certifcate store of the specified certificate thumbprint. Either LocalMachine or CurrentUser.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-KeyVault <String>
The name of the Azure KeyVault that will that contains the exported credential secret.
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-SecretName <String>
The name of the Azure KeyVault secret that contains the exported credential.
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$Credential = Import-PSCredential -Path ./savedcredential.json -SecureKey ( Convertto-SecureString -String
'$ecretK3y' -AsPlainText -Force )
Import a credential from file using a pre-shared key.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>$Credential = Import-PSCredential -Path ./savedcredential.json -Thumbprint
'87BB70A19A7671D389F49AF4C9608B2F381FDD80'
Import a credential from file using a Certificate.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>$Credential = Import-PSCredential -KeyVault 'My-KeyVault' -SecretName 'SavedCred-Secret'
Import a credential from an Azure KeyVault. The user executing the script must be authenticated to Azure with
sufficient permissions to the KeyVault.
RELATED LINKS
SYNOPSIS
Retrieves and decrypts an exported PowerShell Credential from file or Azure KeyVault back into a PSCredential
object.
SYNTAX
Import-PSCredential [-Path] <String> -Thumbprint <String> [-CertificateStore <String>] [<CommonParameters>]
Import-PSCredential [-Path] <String> -SecureKey <SecureString> [<CommonParameters>]
Import-PSCredential -KeyVault <String> -SecretName <String> [<CommonParameters>]
DESCRIPTION
Import-PSCredential is used to retrieve a previously saved PowerShell Credential object from disk
or from Azure KeyVault and returns a PowerShell Credential object [System.Management.Automation.PSCredential] that
can be used within scripts and
Desired State Configurations. When retrieving from disk, the method used to encrypt the credential must be used to
decrypt the credential.
PARAMETERS
-Path <String>
Path to the JSON file that contains the encrypted credential.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-SecureKey <SecureString>
The SecureString that was used as a Pre-Shared-Key for encrypting the credential password.
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Thumbprint <String>
The Thumbprint of the certificate on the local computer that contains the private key of the certificate used
to encrypt the credential password.
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-CertificateStore <String>
Specifies the certifcate store of the specified certificate thumbprint. Either LocalMachine or CurrentUser.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-KeyVault <String>
The name of the Azure KeyVault that will that contains the exported credential secret.
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-SecretName <String>
The name of the Azure KeyVault secret that contains the exported credential.
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$Credential = Import-PSCredential -Path ./savedcredential.json -SecureKey ( Convertto-SecureString -String
'$ecretK3y' -AsPlainText -Force )
Import a credential from file using a pre-shared key.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>$Credential = Import-PSCredential -Path ./savedcredential.json -Thumbprint
'87BB70A19A7671D389F49AF4C9608B2F381FDD80'
Import a credential from file using a Certificate.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>$Credential = Import-PSCredential -KeyVault 'My-KeyVault' -SecretName 'SavedCred-Secret'
Import a credential from an Azure KeyVault. The user executing the script must be authenticated to Azure with
sufficient permissions to the KeyVault.
RELATED LINKS