|
| 1 | +--- |
| 2 | + |
| 3 | +title: Tutorial for bulk inviting B2B collaboration users - Azure Active Directory | Microsoft Docs |
| 4 | +description: In this tutorial, you learn how to use PowerShell and a CSV file to send bulk invitations to external Azure AD B2B collaboration guest users. |
| 5 | + |
| 6 | +services: active-directory |
| 7 | +ms.service: active-directory |
| 8 | +ms.subservice: B2B |
| 9 | +ms.topic: tutorial |
| 10 | +ms.date: 02/11/2020 |
| 11 | + |
| 12 | +ms.author: mimart |
| 13 | +author: msmimart |
| 14 | +manager: celestedg |
| 15 | +ms.reviewer: mal |
| 16 | + |
| 17 | +#customer intent: As a tenant administrator, I want to send B2B invitations to multiple external users at the same time so that I can avoid having to send individual invitations to each user. |
| 18 | + |
| 19 | +ms.collection: M365-identity-device-management |
| 20 | +--- |
| 21 | + |
| 22 | +# Tutorial: Use PowerShell to bulk invite Azure AD B2B collaboration users |
| 23 | + |
| 24 | +If you use Azure Active Directory (Azure AD) B2B collaboration to work with external partners, you can invite multiple guest users to your organization at the same time. In this tutorial, you learn how to use PowerShell to send bulk invitations to external users. Specifically, you do the following: |
| 25 | + |
| 26 | +> [!div class="checklist"] |
| 27 | +> * Prepare a comma-separated value (.csv) file with the user information |
| 28 | +> * Run a PowerShell script to send invitations |
| 29 | +> * Verify the users were added to the directory |
| 30 | +
|
| 31 | +If you don’t have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
| 32 | + |
| 33 | +## Prerequisites |
| 34 | + |
| 35 | +### Install the latest AzureADPreview module |
| 36 | + |
| 37 | +Make sure that you install the latest version of the Azure AD PowerShell for Graph module (AzureADPreview). |
| 38 | + |
| 39 | +First, check which modules you have installed. Open Windows PowerShell as an elevated user (Run as administrator), and run the following command: |
| 40 | + |
| 41 | +```powershell |
| 42 | +Get-Module -ListAvailable AzureAD* |
| 43 | +``` |
| 44 | + |
| 45 | +Based on the output, do one of the following: |
| 46 | + |
| 47 | +- If no results are returned, run the following command to install the AzureADPreview module: |
| 48 | + |
| 49 | + ```powershell |
| 50 | + Install-Module AzureADPreview |
| 51 | + ``` |
| 52 | + |
| 53 | +- If only the AzureAD module shows up in the results, run the following commands to install the AzureADPreview module: |
| 54 | + |
| 55 | + ```powershell |
| 56 | + Uninstall-Module AzureAD |
| 57 | + Install-Module AzureADPreview |
| 58 | + ``` |
| 59 | + |
| 60 | +- If only the AzureADPreview module shows up in the results, but you receive a message that indicates there's a later version, run the following commands to update the module: |
| 61 | + |
| 62 | + ```powershell |
| 63 | + Uninstall-Module AzureADPreview |
| 64 | + Install-Module AzureADPreview |
| 65 | + ``` |
| 66 | + |
| 67 | +You may receive a prompt that you're installing the module from an untrusted repository. This occurs if you haven't previously set the PSGallery repository as a trusted repository. Press **Y** to install the module. |
| 68 | + |
| 69 | +### Get test email accounts |
| 70 | + |
| 71 | +You need two or more test email accounts that you can send the invitations to. The accounts must be from outside your organization. You can use any type of account, including social accounts such as gmail.com or outlook.com addresses. |
| 72 | + |
| 73 | +## Prepare the CSV file |
| 74 | + |
| 75 | +In Microsoft Excel, create a CSV file with the list of invitee user names and email addresses. Make sure to include the **Name** and **InvitedUserEmailAddress** column headings. |
| 76 | + |
| 77 | +For example, create a worksheet in the following format: |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +Save the file as **C:\BulkInvite\Invitations.csv**. |
| 82 | + |
| 83 | +If you don't have Excel, you can create a CSV file in any text editor, such as Notepad. Separate each value with a comma, and each row with a new line. |
| 84 | + |
| 85 | +## Sign in to your tenant |
| 86 | + |
| 87 | +Run the following command to connect to the tenant domain: |
| 88 | + |
| 89 | +```powershell |
| 90 | +Connect-AzureAD -TenantDomain "<Tenant_Domain_Name>" |
| 91 | +``` |
| 92 | + |
| 93 | +For example, `Connect-AzureAD -TenantDomain "contoso.onmicrosoft.com"`. |
| 94 | + |
| 95 | +When prompted, enter your credentials. |
| 96 | + |
| 97 | +## Send bulk invitations |
| 98 | + |
| 99 | +To send the invitations, run the following PowerShell script (where **c:\bulkinvite\invitations.csv** is the path of the CSV file): |
| 100 | + |
| 101 | +```powershell |
| 102 | +$invitations = import-csv c:\bulkinvite\invitations.csv |
| 103 | +
|
| 104 | +$messageInfo = New-Object Microsoft.Open.MSGraph.Model.InvitedUserMessageInfo |
| 105 | +
|
| 106 | +$messageInfo.customizedMessageBody = "Hello. You are invited to the Contoso organization." |
| 107 | +
|
| 108 | +foreach ($email in $invitations) |
| 109 | + {New-AzureADMSInvitation ` |
| 110 | + -InvitedUserEmailAddress $email.InvitedUserEmailAddress ` |
| 111 | + -InvitedUserDisplayName $email.Name ` |
| 112 | + -InviteRedirectUrl https://myapps.microsoft.com ` |
| 113 | + -InvitedUserMessageInfo $messageInfo ` |
| 114 | + -SendInvitationMessage $true |
| 115 | + } |
| 116 | +``` |
| 117 | + |
| 118 | +The script sends an invitation to the email addresses in the Invitations.csv file. You should see output similar to the following for each user: |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +## Verify users exist in the directory |
| 123 | + |
| 124 | +To verify that the invited users were added to Azure AD, run the following command: |
| 125 | + |
| 126 | +```powershell |
| 127 | + Get-AzureADUser -Filter "UserType eq 'Guest'" |
| 128 | +``` |
| 129 | + |
| 130 | +You should see the users that you invited listed, with a user principal name (UPN) in the format *emailaddress*#EXT#\@*domain*. For example, *lstokes_fabrikam.com#EXT#\@contoso.onmicrosoft.com*, where contoso.onmicrosoft.com is the organization from which you sent the invitations. |
| 131 | + |
| 132 | +## Clean up resources |
| 133 | + |
| 134 | +When no longer needed, you can delete the test user accounts in the directory. Run the following command to delete a user account: |
| 135 | + |
| 136 | +```powershell |
| 137 | + Remove-AzureADUser -ObjectId "<UPN>" |
| 138 | +``` |
| 139 | + |
| 140 | +For example: `Remove-AzureADUser -ObjectId "lstokes_fabrikam.com#EXT#@contoso.onmicrosoft.com"` |
| 141 | + |
| 142 | +## Next steps |
| 143 | + |
| 144 | +In this tutorial, you sent bulk invitations to guest users outside of your organization. Next, learn how the invitation redemption process works. |
| 145 | + |
| 146 | +> [!div class="nextstepaction"] |
| 147 | +> [Learn about the Azure AD B2B collaboration invitation redemption process](redemption-experience.md) |
0 commit comments