Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 新AzureADUserAppRoleAssignment扩展_Powershell_Azure_Azure Active Directory_Cmdlets - Fatal编程技术网

Powershell 新AzureADUserAppRoleAssignment扩展

Powershell 新AzureADUserAppRoleAssignment扩展,powershell,azure,azure-active-directory,cmdlets,Powershell,Azure,Azure Active Directory,Cmdlets,我正在创建一个用户并应用应用程序角色,该角色位于使用此cmdlet在Azure中构建的自定义应用程序中,并且运行良好。问题是,我有多个Azure自定义构建的应用程序,它们的角色与我希望用户在每个应用程序中拥有的角色相同。有没有一种方法可以使用此cmdlet,比如说,将-ResourceId设置为多个ServicePrincipal,以允许在每个应用程序中一次性接收此用户,或者我必须逐个执行此操作 我当前的代码: $PasswordProfile = New-Object -TypeName Mi

我正在创建一个用户并应用应用程序角色,该角色位于使用此cmdlet在Azure中构建的自定义应用程序中,并且运行良好。问题是,我有多个Azure自定义构建的应用程序,它们的角色与我希望用户在每个应用程序中拥有的角色相同。有没有一种方法可以使用此cmdlet,比如说,将-ResourceId设置为多个ServicePrincipal,以允许在每个应用程序中一次性接收此用户,或者我必须逐个执行此操作

我当前的代码:

$PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
$PasswordProfile.Password = "<Password>"
$PasswordProfile.EnforceChangePasswordPolicy = $True
New-AzureADUser -DisplayName "<Display Name of User>" -PasswordProfile $PasswordProfile -UserPrincipalName "<developer's test user>@dosinvest.onmicrosoft.com" -AccountEnabled $true -MailNickName "<NickName to use for Mail name>"
$username = "<developer's test user>@dosinvest.onmicrosoft.com"
$app_name = "<Name of Application>"
$app_role_name = "<Display Name of Role within Application>"
$user = Get-AzureADUser -ObjectId "$username"
$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"
$appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId $user.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id
$PasswordProfile=新对象-TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
$PasswordProfile.Password=“”
$PasswordProfile.EnforceChangePasswordPolicy=$True
新AzureADUser-DisplayName”“-PasswordProfile$PasswordProfile-UserPrincipalName“@dosinvest.onmicrosoft.com”
$app_name=“”
$app_role_name=“”
$user=Get AzureADUser-ObjectId“$username”
$sp=获取AzureADServicePrincipal-过滤器“displayName eq'$app_name'”
$appRole=$sp.AppRoles |其中对象{$\u.DisplayName-eq$app\u role\u name}
新AzureADUserAppRoleAssignment-ObjectId$user.ObjectId-PrincipalId$user.ObjectId-ResourceId$sp.ObjectId-Id$appRole.Id

ResourceID
参数将
String
作为基于的输入,因此不可能为其提供多个ID

可能对您有帮助的是
ForEach
。例如,让我们定义应用程序名称数组(注意名称而不是名称):

额外资源:


谢谢@robdy,我没有考虑过使用
ForEach
。在把这个添加到我的脚本中之后,它确实起了作用。非常感谢。
$app_names = "<Name of Application>","<Name of Application2>"
$user = Get-AzureADUser -ObjectId "$username"
$app_role_name = "<Display Name of Role within Application>"

foreach ($n in $app_names) {
  $sp = Get-AzureADServicePrincipal -Filter "displayName eq '$n'"
  $appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }
  New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId $user.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id
}