你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

New-AzureADUserAppRoleAssignment

向应用程序角色分配用户。

语法

New-AzureADUserAppRoleAssignment
   -ObjectId <String>
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   -Id <String>
   -PrincipalId <String>
   -ResourceId <String>
   [<CommonParameters>]

说明

New-AzureADUserAppRoleAssignment cmdlet 将用户分配到 Azure Active Directory (AD) 中的应用程序角色。

示例

示例 1:将用户分配到没有角色的应用程序

# Get AppId of the app to assign the user to

$appId = Get-AzureADApplication -SearchString "<Your App's display name>"

# Get the user to be added

$user = Get-AzureADUser -searchstring "<Your user's UPN>"

# Get the service principal for the app you want to assign the user to

$servicePrincipal = Get-AzureADServicePrincipal -Filter "appId eq 'appId'"

# Create the user app role assignment

New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId $user.ObjectId -ResourceId $servicePrincipal.ObjectId -Id ([Guid]::Empty)

此命令将用户分配到没有任何角色的应用程序。

示例 2:将用户分配到应用程序中的特定角色

$username = "<You user's UPN>"
$appname = "<Your App's display name>"
$spo = Get-AzureADServicePrincipal -Filter "Displayname eq '$appname'"
$user = Get-AzureADUser -ObjectId $username
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId $user.ObjectId -ResourceId $spo.ObjectId -Id $spo.Approles[1].id

此 cmdlet 分配给指定的用户,该用户使用$spo指定 ID 的应用程序角色。Approles[1].id。有关如何检索应用程序的应用程序角色的详细信息,请参阅 -Id 参数的说明。

参数

-Id

要分配的应用角色的 ID。 为没有任何角色的应用程序创建新的应用角色分配或要分配给用户的角色 ID 时,请提供空 GUID。

可以通过检查应用程序对象的 AppRoles 属性来检索应用程序的角色:

Get-AzureadApplication -SearchString "Your Application display name" | select Approles | Fl 

此 cmdlet 返回在应用程序中定义的角色列表:

AppRoles : {class AppRole {
         AllowedMemberTypes: System.Collections.Generic.List1[System.String]
         Description: <description for this role>
         DisplayName: <display name for this role>
         Id: 97e244a2-6ccd-4312-9de6-ecb21884c9f7
         IsEnabled: True
         Value: <Value that will be transmitted as a claim in a token for this role>
       }
       }
Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-InformationAction

指定此 cmdlet 如何响应信息事件。 此参数的可接受值为:

  • 继续
  • 忽略
  • 查询
  • SilentlyContinue
  • 停止
  • 挂起
Type:ActionPreference
Aliases:infa
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InformationVariable

指定信息变量。

Type:String
Aliases:iv
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ObjectId

指定要向其分配新应用角色的 Azure AD 中将用户 (的 ID 指定为 UPN 或 ObjectId)

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-PrincipalId

为其分配新应用角色的主体的对象 ID。 向用户分配新角色时,请提供该用户的对象 ID。

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-ResourceId

为其分配用户角色的应用程序的服务主体的对象 ID。

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False