From 8180112ee5b0490fd83193a39036d56ab06f4156 Mon Sep 17 00:00:00 2001 From: Michel Pauwels Date: Mon, 24 Oct 2022 11:55:44 +0200 Subject: [PATCH] Update Assign AccessPolicy to KeyVault.ps1 Migrated to Az Powershell commands & add TenantId as an extra parameter --- Azure/Assign AccessPolicy to KeyVault.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Azure/Assign AccessPolicy to KeyVault.ps1 b/Azure/Assign AccessPolicy to KeyVault.ps1 index e88077e..a933794 100644 --- a/Azure/Assign AccessPolicy to KeyVault.ps1 +++ b/Azure/Assign AccessPolicy to KeyVault.ps1 @@ -1,3 +1,6 @@ +# The ID of the tenant in which the keyVault is located +$tenantId = '' + # The ID of the subscription in which the keyVault is located $subscriptionId = '' @@ -13,14 +16,14 @@ $keyVaultName = '' [String[]] $permissionsToCertificates = ("get","list","update","create","import","delete","recover","Managecontacts","Getissuers","Listissuers","Setissuers","Deleteissuers","Manageissuers","Purge") # Login to Azure -Login-AzureRmAccount +Login-AzAccount -SubscriptionId $subscriptionId -TenantId $tenantId # Select the correct subscription -Select-AzureRmSubscription -SubscriptionId $subscriptionId +Set-AzContext -SubscriptionId $subscriptionId -TenantId $tenantId try{ # Create/Update an AccessPolicy for the specified user, with the specified permissions. - Set-AzureRmKeyVaultAccessPolicy -VaultName $keyVaultName -ObjectId $userObjectId -PermissionsToSecrets $permissionsToSecrets -PermissionsToKeys $permissionsToKeys -PermissionsToCertificates $permissionsToCertificates -BypassObjectIdValidation + Set-AzKeyVaultAccessPolicy -VaultName $keyVaultName -ObjectId $userObjectId -PermissionsToSecrets $permissionsToSecrets -PermissionsToKeys $permissionsToKeys -PermissionsToCertificates $permissionsToCertificates -BypassObjectIdValidation Write-Information "Access policy has been created." } catch