简体   繁体   English

使用 Powershell 将角色分配给多个用户和系统标识?

[英]Assign Roles to multiple users and System Identity using Powershell?

I have requirement to assign Azure Roles to multiple users on subscription scope and Reader role to Managed Identity-Storage Account.我需要将 Azure 角色分配给订阅 scope 上的多个用户,并将读者角色分配给托管身份存储帐户。

1.Assign Azure RBAC roles to multiple users 1.将Azure RBAC角色分配给多个用户

2.Assign system assigned managed identity to existing Virtual Machine, Role Reader 2.Assign system assigned managed identity to existing Virtual Machine, 角色读取器

Here is the script.这是脚本。

$vm-(Get-Azum-ResourceGroupName <Resourcegrpupname> -Name <VMName>),identity.principalid 

New-AzRoleAssignment -Objectid <Objectid> -RoleDefinitionName "Reader" -Scope "/subscriptions/<Id>/resourceGroups/VResourcregroup Name>/providers/Microsoft.Storage/StoragrAccounts/<storageaccoumt>

New-AzRoleAssignment -ObjectId <ID> -RoleDefinationName <RBACRule> -Scope '/Subscription/<I'D>`
`

Script is working,butneed to assign same roles to multiple users.脚本正在运行,但需要将相同的角色分配给多个用户。

Assign Azure RBAC roles to multiple users":将 Azure RBAC角色分配给多个用户”:

To assign roles to multiple users at the same time, simply form a group by adding users who need the "reader" role assignments.要同时将角色分配给多个用户,只需通过添加需要“读者”角色分配的用户来组成一个

Created a group under AzureAD -> Groups :AzureAD -> Groups下创建了一个组:

在此处输入图像描述


new-azroleassignment -objectID <ObjectId of group> -Roledefinitionname "Reader"  -scope "/subscriptions/<subscriptionID>/resourceGroups/xxxxRG/..." #Give scope of the resource as per the requirements.

Output: Output:

在此处输入图像描述

  1. Assign system assigned managed identity to existing Virtual Machine:将系统分配的托管标识分配给现有虚拟机:

Previously, System assigned identity status is Off :以前,系统分配的身份状态为Off

在此处输入图像描述

If not for any particular roles, You can directly update VM configurations/identities by using below commands :如果不是针对任何特定角色,您可以使用以下命令直接更新 VM 配置/身份

$vminfo = Get-AzVM -ResourceGroupName xxxxxxRG -Name xxxxVM
Update-AzVM -ResourceGroupName xxxxxxRG -VM $vminfo -IdentityType SystemAssigned 

在此处输入图像描述

System assigned identity status is "ON" now:系统分配的身份状态现在是“ON”

在此处输入图像描述

  1. Assign system assigned managed identity to existing Virtual Machine, Role Reader :将系统分配的托管标识分配给现有虚拟机,角色读取器

Using PowerShell, you may configure identities for the appropriate app roles under App services.使用 PowerShell,您可以在应用服务下为适当的应用角色配置身份。 To work with VMs, use AzCLI command az vm identity to assign the system-assigned identity as shown here:要使用 VM,请使用AzCLI命令az vm identity来分配系统分配的标识,如下所示:

az vm identity assign -g xxxxResourceGroup -n xxxxVirtualMachineName --role Reader --scope /subscriptions/<subscriptionID>/resourceGroups/xxxxRG

Assigned :分配

在此处输入图像描述

Updated:更新:


SID=$(az resource list -n newVM --query [*].identity.principalId --out tsv)
az role assignment create --assignee $SID --role 'Reader' --scope /subscriptions/<subscriptionID>/resourceGroups/xxxxRG/providers/Microsoft.Storage/storageAccounts/<storageaccount>

在此处输入图像描述

  • Assigning Azure RBAC roles with scope as storage account:使用 scope 作为存储帐户分配 Azure RBAC角色:
new-azroleassignment -objectID <ObjectId of group> -Roledefinitionname "Reader"  -scope "/subscriptions/<subscriptionID>/resourceGroups/xxxxRG/providers/Microsoft.Storage/storageAccounts/<storageaccount>

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建 Azure 角色并将其分配给 Azure AD 用户自动使用 Azure Cli 到 Z531BDA184AD41B22A7533 脚本 - Create and assign Azure roles to Azure AD users automatically using Azure Cli though Powershell scripts Azure ARM 模板,将多个角色分配给自动化帐户中的托管身份 - Azure ARM Template, assign multiple roles to managed identity in Automation Account 将角色添加到 AppRegistration 并将用户分配给角色 - Add Roles to AppRegistration and Assign users to Roles 如何使用循环 powershell 分配多个用户访问一个应用程序组? - How to use loop powershell to assign multiple users to access an app group? 如何为 Azure Active Directory 中的用户分配角色 - How to assign roles to the users in Azure Active Directory 如何将 Keycloak 角色分配给 IDP 用户 - How to assign Keycloak Roles to IDP Users 是否可以使用 PowerShell 中的服务主体为新创建的应用程序分配角色和范围? - Is it possible to assign roles and scopes to a newly created app using a Service Principal in PowerShell? Azure AD:如何为其他租户的用户分配应用角色 - Azure AD: How assign App roles for users from another tenant 如何使用 Azure Powershell 检索应用系统分配的标识 Object Id - How to retrieve App System Assigned Identity Object Id using Azure Powershell 如何使用二头肌将服务总线实体上的正确角色分配给 Azure 功能托管标识? - How to assign correct roles on Service Bus entities to Azure functions managed identity with Bicep?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM