通过Powershell将来宾用户添加到Azure AD组不起作用

时间:2020-11-11 16:27:55

标签: azure-powershell

有人可以通过以下脚本帮助我吗?我正在尝试将访客添加到我的Azure AD中,并将其添加到Azure AD组中。我可以轻松地添加用户,但是在脚本运行时,不会将用户添加到组中。如果我打开powershell并运行同一行来添加用户,那么它将起作用。

foreach ($email in $invitations)
   {
      New-AzureADMSInvitation `
      -InvitedUserEmailAddress $email.UserPrincipalName `
      -InvitedUserDisplayName $email.name `
      -InviteRedirectUrl https://myapps.microsoft.com `
      -InvitedUserMessageInfo $messageInfo `
      -SendInvitationMessage $true    
   }
   
    # Add same guest users to Microsoft 365 Group
    # wait a few seconds so the new guest user objects are available to add to the group
    Start-Sleep -Second 30
    foreach ($email in $invitations) {Add-AzureADGroupMember -RefObjectId (Get-AzureADUser | Where { $_.Mail -eq $email.InvitedUserEmailAddress }).ObjectID -ObjectId (Get-AzureADGroup | Where { $_.DisplayName -eq "TestAzureADGroupALNG" }).ObjectID}

预先感谢

0 个答案:

没有答案