如何知道天蓝色角色分配已经存在

时间:2019-04-04 07:07:30

标签: azure powershell

我正在尝试获取当前角色分配状态。

例如:我为我的网络应用分配了贡献者角色

New-AzureRmRoleAssignment -ObjectId 43fddad0-xxxx-xxxx-xxxx-665033f5fbf0 -RoleDefinitionName "Storage Blob Data Contributor" -Scope "/subscriptions/4364666b-xxxx-xxxx-xxxx-47158904c439/resourceGroups/devt002RG/providers/Microsoft.Storage/storageAccounts/devt002"

当我再次在VSTS中运行以上命令时,它将给出错误消息

2019-04-02T10:22:58.2614183Z ##[error]The role assignment already exists.

我只想获取角色(存储Blob数据贡献者)分配到我的Web应用程序的当前状态,如果该状态已经存在,我将跳过分配。

我尝试过:

Get-AzureRmRoleAssignment -Scope "/subscriptions/4364666b-xxxx-xxxx-xxxx-47158904c439/resourceGroups/devt002RG/providers/Microsoft.Storage/storageAccounts/devt002"
Get-AzureRmRoleAssignment -Id 43fddad0-xxxx-xxxx-xxxx-665033f5fbf0

1 个答案:

答案 0 :(得分:1)

好吧,您使用的是正确的命令,您只需要围绕它构建一些逻辑即可确定分配是否已经存在。

如果您事先知道GUID:

Get-AzRoleAssignment -ObjectId "GUID"

是最简单的检查方法