PowerShell ConvertTo-String

Hi

I have the following code to create PSCredential and get the password value from key vault

$Username = ‘Test’
$password = ConvertTo-SecureString (Get-AzKeyVaultSecret -VaultName KeyVault01 -Name ‘deploy’).SecretValue -AsPlainText -Force
$credential = New-Object PSCredential($Username, $password)

Running the command I get the following results where the password is not converted
UserName Password


deploy System.Security.SecureString

Does anyone know how to resolve this, I need to access key to retrive password so it can be authenticated to remote computer share

Regards

Raxso123

In order to decrypt the password, you need to do the following:

PS C:\Users\rasim>
 $password = ConvertTo-SecureString "P@ssw0rd!" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ("raxman01", $password)

PS C:\Users\rasim> $credential

UserName                     Password
--------                     --------
raxman01 System.Security.SecureString

PS C:\Users\rasim> $credential.GetNetworkCredential().password
P@ssw0rd!

Then you can validate that the Get-AzKeyVaultSecret command is returning a string value to encrypt as a secure string.