本文介绍如何使用 Azure PowerShell 授予对 Azure 预留的基于角色的访问控制(RBAC)访问权限。 若要在 Azure 门户中查看和管理 RBAC 访问权限,请参阅 查看和管理 Azure 预留的权限。
注释
建议使用 Azure Az PowerShell 模块与 Azure 交互。 请参阅安装 Azure PowerShell 以开始使用。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az。
使用 PowerShell 授予访问权限
以下用户类型可以委托对他们能够访问的所有预留订单进行访问管理:
- 拥有预订订单所有者访问权限的用户
- 具有提升访问权限的用户
- 用户访问管理员
使用 PowerShell 授予访问权限时,无法在 Azure 门户中查看角色。 相反,可以使用下一部分中的 get-AzRoleAssignment 命令查看角色。
为所有预留分配所有者角色
使用以下 PowerShell 脚本向用户授予 RBAC 对其Microsoft Entra 租户(目录)中的所有预留订单的访问权限。
Import-Module Az.Accounts
Import-Module Az.Resources
Connect-AzAccount -Tenant <TenantId>
$response = Invoke-AzRestMethod -Path /providers/Microsoft.Capacity/reservations?api-version=2020-06-01 -Method GET
$responseJSON = $response.Content | ConvertFrom-JSON
$reservationObjects = $responseJSON.value
foreach ($reservation in $reservationObjects)
{
$reservationOrderId = $reservation.id.substring(0, 84)
Write-Host "Assigning Owner role assignment to "$reservationOrderId
New-AzRoleAssignment -Scope $reservationOrderId -ObjectId <ObjectId> -RoleDefinitionName Owner
}
使用 PowerShell 脚本分配所有权角色且该脚本成功运行时,不会返回成功消息。
参数
参数 -ObjectId 是用户、组或服务主体的 Microsoft Entra ObjectId。
- 类型:字符串
-
别名:
IdPrincipalId - 位置:已命名
- 默认值:无
- 接受管道输入:True
- 接受通配符:False
参数 -TenantId 是租户的唯一标识符。
- 类型:字符串
- 位置:5
- 默认值:无
- 接受管道输入:False
- 接受通配符:False
授予租户级访问权限
需要 具有用户访问管理员 权限,然后才能在租户级别授予用户或组以下角色:
- 预留管理员
- 预订贡献者
- 预订读取器
若要在租户级别获取用户访问管理员权限,请按照步骤 提升访问权限。
在租户级别添加预留管理员角色、预留参与者角色或预留读者角色
只有具有全局管理员角色的用户才能从 Azure 门户分配这些角色。
- 登录到 Azure 门户并转到“预留”。
- 选择可以访问的预留。
- 在页面顶部,选择 “角色分配”。
- 选择“ 角色 ”选项卡。
- 若要进行修改,请使用访问控制将用户添加为预留管理员、预留参与者或预留读者。
使用 Azure PowerShell 脚本在租户级别添加预留管理员角色
使用以下 Azure PowerShell 脚本在租户级别添加预留管理员角色。
Import-Module Az.Accounts
Import-Module Az.Resources
Connect-AzAccount -Tenant <TenantId>
New-AzRoleAssignment -Scope "/providers/Microsoft.Capacity" -PrincipalId <ObjectId> -RoleDefinitionName "Reservations Administrator"
参数
参数 -ObjectId 是用户、组或服务主体的 Microsoft Entra ObjectId。
- 类型:字符串
-
别名:
IdPrincipalId - 位置:已命名
- 默认值:无
- 接受管道输入:True
- 接受通配符:False
参数 -TenantId 是租户的唯一标识符。
- 类型:字符串
- 位置:5
- 默认值:无
- 接受管道输入:False
- 接受通配符:False
使用 Azure PowerShell 脚本在租户级别添加预留参与者角色
使用以下 Azure PowerShell 脚本在租户级别添加预留参与者角色。
Import-Module Az.Accounts
Import-Module Az.Resources
Connect-AzAccount -Tenant <TenantId>
New-AzRoleAssignment -Scope "/providers/Microsoft.Capacity" -PrincipalId <ObjectId> -RoleDefinitionName "Reservations Contributor"
参数
参数 -ObjectId 是用户、组或服务主体的 Microsoft Entra ObjectId。
- 类型:字符串
-
别名:
IdPrincipalId - 位置:已命名
- 默认值:无
- 接受管道输入:True
- 接受通配符:False
参数 -TenantId 是租户的唯一标识符。
- 类型:字符串
- 位置:5
- 默认值:无
- 接受管道输入:False
- 接受通配符:False
使用 Azure PowerShell 脚本在租户级别分配预留读取者角色
使用以下 Azure PowerShell 脚本在租户级别分配预留读取者角色。
Import-Module Az.Accounts
Import-Module Az.Resources
Connect-AzAccount -Tenant <TenantId>
New-AzRoleAssignment -Scope "/providers/Microsoft.Capacity" -PrincipalId <ObjectId> -RoleDefinitionName "Reservations Reader"
参数
参数 -ObjectId 是用户、组或服务主体的 Microsoft Entra ObjectId。
- 类型:字符串
-
别名:
IdPrincipalId - 位置:已命名
- 默认值:无
- 接受管道输入:True
- 接受通配符:False
参数 -TenantId 是租户的唯一标识符。
- 类型:字符串
- 位置:5
- 默认值:无
- 接受管道输入:False
- 接受通配符:False