Take the content of the $SASKeyJson variable and paste it into this URL: jsonlint.com
But if you're just looking to retrieve the secret, try adding the -AsPlainText switch to the cmdlet.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi Team,
I am using the below script on Windows Server 2019 to fetch details from Keyvault using PowerShell:
$User = user1@jaswant .com
$SecurePassword = Get-Content "D:\PSScripts\accessPwd.dat" | ConvertTo-SecureString
$PSCredential = New-Object System.Management.Automation.PSCredential($User,$SecurePassword)
$Password = $PSCredential.GetNetworkCredential().Password
az login -u $User -p $Password
$SASKeyJson = Get-AzKeyVaultSecret -name "secret1" -vaultname "abcxyzvault"
$SASKey = $SASKeyJson | ConvertFrom-Json
$KeyValue = $SASKey.value
$KeyValue
Set-Content -Path "D:\PSScripts\KeyValue.txt" -Value $KeyValue
$SASKeyJson = Get-AzKeyVaultSecret -name "secret2" -vaultname "abcxyzvault"
$SASKey = $SASKeyJson | ConvertFrom-Json
$KeyValue = $SASKey.value
$KeyValue
Set-Content -Path "D:\PSScripts\KeyPWD.txt" -Value $KeyValue
$SASKeyJson = Get-AzKeyVaultSecret -name "secret3" -vaultname "abcxyzvault"
$SASKey = $SASKeyJson | ConvertFrom-Json
$KeyValue = $SASKey.value
$KeyValue
Set-Content -Path "D:\PSScripts\KeyUser.txt" -Value $KeyValue
The authentication part is working fine.
But getting below error after that:
*ConvertFrom-Json : Invalid JSON primitive: Microsoft.Azure.Commands.KeyVault.Models.PSKeyVaultSecret.
At D:\PSScript\GetKey1.ps1:3 char:25
ConvertFrom-Json : Invalid JSON primitive: Microsoft.Azure.Commands.KeyVault.Models.PSKeyVaultSecret.
At D:\PSScript\GetKey1.ps1:8 char:25
Get-AzKeyVaultSecret : A parameter cannot be found that matches parameter name 'vault-name'.
At D:\PSScript\GetKey1.ps1:12 char:61
ConvertFrom-Json : Invalid JSON primitive: Microsoft.Azure.Commands.KeyVault.Models.PSKeyVaultSecret.
At D:\PSScript\GetKey1.ps1:13 char:25
Take the content of the $SASKeyJson variable and paste it into this URL: jsonlint.com
But if you're just looking to retrieve the secret, try adding the -AsPlainText switch to the cmdlet.