To retrieve the ObjectId of an Azure Key Vault, you can use the Azure PowerShell module to run a script inline. Here's an example of how to do it:
- Open PowerShell and log in to your Azure account using the
Connect-AzAccount
cmdlet. - Create a new Key Vault using the
New-AzKeyVault
cmdlet. Make sure to include the-EnabledForDeployment
parameter, as this will allow you to retrieve the ObjectId later on.
powershellCopy code
$resourceGroup = "myResourceGroup"
$vaultName = "myKeyVault"
New-AzKeyVault -ResourceGroupName $resourceGroup -Name $vaultName -EnabledForDeployment
```
1. Retrieve the ObjectId of the Key Vault using the **`Get-AzResource`** cmdlet. This cmdlet returns an Azure Resource Manager resource, which includes the ObjectId of the Key Vault.
powershellCopy code
$keyVault = Get-AzResource -ResourceGroupName $resourceGroup -ResourceType "Microsoft.KeyVault/vaults" -ResourceName $vaultName
$keyVault.ObjectId ```
The **`Get-AzResource`** cmdlet is used to retrieve the Key Vault resource, and the **`ObjectId`** property is used to retrieve the ObjectId of the Key Vault.
That's it! You can now use this ObjectId in other scripts and commands to manage your Key Vault.