共用方式為


New-AzureRmRoleAssignment

在指定的範圍內,將指定的 RBAC 角色指派給指定的主體。

警告

自 2024 年 2 月 29 日起,AzureRM PowerShell 模組已正式淘汰。 建議使用者從 AzureRM 遷移至 Az PowerShell 模組,以確保持續支援和更新。

雖然 AzureRM 模組可能仍可運作,但不再維護或支援它,但會根據用戶的判斷權和風險放置任何繼續使用。 如需轉換至 Az 模組的指引,請參閱我們的 移轉資源

Syntax

New-AzureRmRoleAssignment
   -ObjectId <Guid>
   -Scope <String>
   -RoleDefinitionName <String>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmRoleAssignment
   -ObjectId <Guid>
   -ResourceGroupName <String>
   -RoleDefinitionName <String>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmRoleAssignment
   -ObjectId <Guid>
   -ResourceGroupName <String>
   -ResourceName <String>
   -ResourceType <String>
   [-ParentResource <String>]
   -RoleDefinitionName <String>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmRoleAssignment
   -ObjectId <Guid>
   [-Scope <String>]
   -RoleDefinitionName <String>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmRoleAssignment
   -ObjectId <Guid>
   -Scope <String>
   -RoleDefinitionId <Guid>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmRoleAssignment
   -SignInName <String>
   -ResourceGroupName <String>
   -RoleDefinitionName <String>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmRoleAssignment
   -SignInName <String>
   -ResourceGroupName <String>
   -ResourceName <String>
   -ResourceType <String>
   [-ParentResource <String>]
   -RoleDefinitionName <String>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmRoleAssignment
   -SignInName <String>
   [-Scope <String>]
   -RoleDefinitionName <String>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmRoleAssignment
   -ApplicationId <String>
   -ResourceGroupName <String>
   -RoleDefinitionName <String>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmRoleAssignment
   -ApplicationId <String>
   -ResourceGroupName <String>
   -ResourceName <String>
   -ResourceType <String>
   [-ParentResource <String>]
   -RoleDefinitionName <String>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmRoleAssignment
   -ApplicationId <String>
   [-Scope <String>]
   -RoleDefinitionName <String>
   [-AllowDelegation]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]

Description

使用 New-AzureRMRoleAssignment 命令來授與存取權。 將適當的 RBAC 角色指派給適當的 RBAC 角色,以授與存取權。 若要授與整個訂用帳戶的存取權,請在訂用帳戶範圍指派角色。 若要授與訂用帳戶內特定資源群組的存取權,請在資源群組範圍指派角色。 必須指定指派的主旨。 若要指定使用者,請使用 SignInName 或 Microsoft Entra ObjectId 參數。 若要指定安全組,請使用 Microsoft Entra ObjectId 參數。 若要指定 Microsoft Entra 應用程式,請使用 ApplicationId 或 ObjectId 參數。 指派的角色必須使用 RoleDefinitionName 參數來指定。 可以指定授與存取權的範圍。 默認為選取的訂用帳戶。 您可以使用下列其中一個參數組合來指定指派的範圍。 範圍 - 這是從 /subscriptions/<subscriptionId> b 開始的完整範圍。 ResourceGroupName - 授與指定資源群組的存取權。 c. ResourceName、ResourceType、ResourceGroupName 和 (選擇性地) ParentResource - 在資源群組內指定要授與存取權的特定資源。

範例

範例 1

PS C:\> New-AzureRmRoleAssignment -ResourceGroupName rg1 -SignInName allen.young@live.com -RoleDefinitionName Reader -AllowDelegation

授與讀者角色存取權給資源群組範圍中的使用者,並授與可供委派的角色指派

範例 2

PS C:\> Get-AzureRMADGroup -SearchString "Christine Koch Team"

          DisplayName                    Type                           Id
          -----------                    ----                           --------
          Christine Koch Team                                           2f9d4375-cbf1-48e8-83c9-2a0be4cb33fb

PS C:\> New-AzureRmRoleAssignment -ObjectId 2f9d4375-cbf1-48e8-83c9-2a0be4cb33fb -RoleDefinitionName Contributor  -ResourceGroupName rg1

授與安全組的存取權

範例 3

PS C:\> New-AzureRmRoleAssignment -SignInName john.doe@contoso.com -RoleDefinitionName Owner -Scope "/subscriptions/86f81fc3-b00f-48cd-8218-3879f51ff362/resourcegroups/rg1/providers/Microsoft.Web/sites/site1"

在資源上授與使用者存取權 (網站)

範例 4

PS C:\> New-AzureRMRoleAssignment -ObjectId 5ac84765-1c8c-4994-94b2-629461bd191b -RoleDefinitionName "Virtual Machine Contributor" -ResourceName Devices-Engineering-ProjectRND -ResourceType Microsoft.Network/virtualNetworks/subnets -ParentResource virtualNetworks/VNET-EASTUS-01 -ResourceGroupName Network

授與巢狀資源群組的存取權(子網)

範例 5

PS C:\> $servicePrincipal = New-AzureRmADServicePrincipal -DisplayName "testServiceprincipal"
PS C:\> New-AzureRmRoleAssignment -RoleDefinitionName "Reader" -ApplicationId $servicePrincipal.ApplicationId

授與讀取者對服務主體的存取權

參數

-AllowDelegation

建立角色指派時委派旗標。

類型:SwitchParameter
Position:Named
預設值:False
必要:False
Accept pipeline input:False
Accept wildcard characters:False

-ApplicationId

ServicePrincipal 的應用程式標識碼

類型:String
Aliases:SPN, ServicePrincipalName
Position:Named
預設值:None
必要:True
Accept pipeline input:True
Accept wildcard characters:False

-DefaultProfile

用於與 azure 通訊的認證、帳戶、租用戶和訂用帳戶

類型:IAzureContextContainer
Aliases:AzureRmContext, AzureCredential
Position:Named
預設值:None
必要:False
Accept pipeline input:False
Accept wildcard characters:False

-ObjectId

使用者、群組或服務主體的 Microsoft Entra Objectid。

類型:Guid
Aliases:Id, PrincipalId
Position:Named
預設值:None
必要:True
Accept pipeline input:True
Accept wildcard characters:False

-ParentResource

階層中的父資源(使用 ResourceName 參數指定的資源)。 應該只與 ResourceGroupName、ResourceType 和 ResourceName 參數搭配使用,以識別資源的相對 URI 形式建構階層式範圍。

類型:String
Position:Named
預設值:None
必要:False
Accept pipeline input:True
Accept wildcard characters:False

-ResourceGroupName

資源組名。 建立在指定資源群組上有效的指派。 搭配 ResourceName、ResourceType 和 (選擇性)ParentResource 參數使用時,命令會以識別資源的相對 URI 形式建構階層式範圍。

類型:String
Position:Named
預設值:None
必要:True
Accept pipeline input:True
Accept wildcard characters:False

-ResourceName

資源名稱。 例如 storageaccountprod。 應該只與 ResourceGroupName、ResourceType 和 (選擇性)ParentResource 參數搭配使用,以識別資源的相對 URI 形式建構階層式範圍。

類型:String
Position:Named
預設值:None
必要:True
Accept pipeline input:True
Accept wildcard characters:False

-ResourceType

資源類型。 例如 Microsoft.Network/virtualNetworks。 應該只能與 ResourceGroupName、ResourceName 和 (選擇性)ParentResource 參數搭配使用,以識別資源的相對 URI 形式建構階層式範圍。

類型:String
Position:Named
預設值:None
必要:True
Accept pipeline input:True
Accept wildcard characters:False

-RoleDefinitionId

需要指派給主體的 RBAC 角色識別碼。

類型:Guid
Position:Named
預設值:None
必要:True
Accept pipeline input:True
Accept wildcard characters:False

-RoleDefinitionName

需要指派給主體的 RBAC 角色名稱,例如讀者、參與者、虛擬網絡 管理員 istrator 等。

類型:String
Position:Named
預設值:None
必要:True
Accept pipeline input:True
Accept wildcard characters:False

-Scope

角色指派的範圍。 以相對 URI 的格式。 例如“/subscriptions/9004a9fd-d58e-48dc-aeb2-4a4aec58606f/resourceGroups/TestRG”。 如果未指定,將會在訂用帳戶層級建立角色指派。 如果指定,它應該以 “/subscriptions/{id}” 開頭。

類型:String
Position:Named
預設值:None
必要:True
Accept pipeline input:True
Accept wildcard characters:False

-SignInName

用戶的電子郵件地址或用戶主體名稱。

類型:String
Aliases:Email, UserPrincipalName
Position:Named
預設值:None
必要:True
Accept pipeline input:True
Accept wildcard characters:False

輸入

Guid

String

輸出

PSRoleAssignment

備註

關鍵詞:azure, azurerm, arm, 資源, 管理, 管理員, 資源, 群組, 範本, 部署