Trying to import multiple access policies into multiple key vaults in a Azure subscription.
I was able to get an export and populate to CSV exactly what I needed.
Problem I am having is on the import-csv foreach-object. Because Key vault requires comma separated values on the permissions keys, secrets and certificate it will not work with my command as its looking for a single variable.
Example. -PermissionsToKeys All,Get,Update
My PowerShell command.
Import-Csv -Path "C:\temp\kv-policies.csv" | ForEach-Object {
Set-AzKeyVaultAccessPolicy -VaultName $_.KeyVaultName -UserPrincipalName $_.UPN -PermissionsToCertificates $_.PermissionsToCertificatesStr -PermissionsToKeys $_.PermissionsToKeysStr -PermissionsToSecrets $_.PermissionsToSecretsStr}
Error
Set-AzKeyVaultAccessPolicy : Cannot validate argument on parameter 'PermissionsToCertificates'. The argument "string Substring(int startIndex), string Substring(int startIndex, int length)" does not belong to the set "all,get,list,delet e,create,import,update,managecontacts,getissuers,listissuers,setissuers,deleteissuers,manageissuers,recover,purge,backu p,restore" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again. At line:2 char:112
- ... sionsToCertificates $_.PermissionsToCertificatesStr.Substring -Permis ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~- CategoryInfo : InvalidData: (:) [Set-AzKeyVaultAccessPolicy], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.KeyVault.SetAzureKeyVaultAcces sPolicy

