Hello @Vishwa teja Devarakonda ,
Thank you for reaching out Microsoft Q&A.
I understand that you want to retrieve a secret using PowerShell on a virtual machine (VM). I successfully configured a secret in an Azure Key Vault and retrieved it on my VM using PowerShell.
Below are the steps I followed:
- Key Vault Access Configuration:
- While creating the Key Vault, I selected Azure Role-Based Access Control (RBAC) as the permission model.
-
- Assign Role and Create Secret:
- Before creating the secret in the Key Vault, I assigned the Key Vault Administrator role to key vault.
- Then, I created the secret in the Key Vault.
- Enable System-Assigned Managed Identity for the VM:
- In the Azure portal, navigate to your VM and go to Security > Identity > System Assigned, and set it to ON.
-
- Retrieve the Secret Using PowerShell:
- Open PowerShell as an administrator on the VM and run the following commands:
Install-module az Connect-AzAccount -Tenant <your_tenant_id> Get-AzKeyVaultSecret -VaultName "<your_vault_name>" -Name "<your_secret_name>" -AsPlainText
-
- NOTE: Replace
<your_tenant_id>
with your actual tenant ID,<your_vault_name>
with the name of your Key Vault, and<your_secret_name>
with the name of your secret.
- Open PowerShell as an administrator on the VM and run the following commands:
Hope this helps. Do let us know if you any further queries.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful. And, if you have any further query do let us know.
Regards,
Goutam Pratti.