New-AzureADUserAppRoleAssignment

將使用者指派到應用程式角色。

Syntax

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

Description

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 指定的應用程式角色。Approles[1].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
  • Stop
  • 暫止
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 中,將使用者 (識別碼指定為 UPN 或 ObjectId)

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

-PrincipalId

指派新應用程式角色之主體的物件識別碼。 將新角色指派給使用者時,請提供使用者的物件識別碼。

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

-ResourceId

指派使用者角色之應用程式之服務主體的物件識別碼。

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