Azure Identity And Access Management Part 18 – Azure Active Directory – Business-to-Business (B2B) And Guest User 6 – Bulk Invitation Of B2B Guest User Using Powershell
Hope you all are doing good!!!
In our last post, we have discussed on, how to Configure Conditional Access Policy And Multi-Factor Authentication (MFA) For Guest User . Today In this article, we will continue Azure AD Business-to-Business (B2B) And Guest User and discuss how to Invite multiple B2B Guest Users Using Powershell.
If you have missed our previous articles on Azure Identity And Access Management (IAM), please check it in following links.
Bulk Invitation Of B2B Guest User :
Now a day more organisations and groups are looking for a online collaboration and preferring to increase in online interaction instead of face to face interaction. For example they are now adopting Microsoft Teams for meetings and collaboration. In this case Organizations needs to send invitation to their external or B2B user and sharing data and resources. Azure facilitate us to send a bulk invite email to all the external guest. We can achieve this through Azure Portal as well as using powershell command line.
Today, in this articles, we will use PowerShell commands to invite guest users in a bulk.
Exercise Lab :
Now the requirement is to invite all guest user in a bulk. We will devide all task into three different section
- Prepare a comma-separated value (.csv) file with the user information – As shown in the following figure, let’s create a .CSV file and store in our local drive.
Add user detail for all external/guest users we want to invite. As shown in the following figure, we need to provide User Display Name and their Email id.
- Run a PowerShell script to send invitations – We have csv file with all user information. Now in this section we will execute our power shell to invite all our guest users. Lets follow the following steps.
Step 1 – First open Window PowerShell as an administration and verify if we have required module installed. We need AzureADPreview Module to complete our exercise as show in the following figure. We can execute following cmdlet.
Get-Module -ListAvailable AzureAD*
Step 2 – As we can see in the above figure, we have already installed the require module. If wit is not installed then we need to execute following command line to install AzureADPreview Module.
Step 3 – As we have required module installed, the next is to import our csv file using following cmdlet as showing in the following figure.
$GuestUsers = import-csv 'C:\MANAS DATA\AZURE\Azure_AZ-104\Azure IAM ( Azure AD)\B2B Colabaration and Guest User in Azure AD\PowerShell to bulk invite Azure AD B2B Guest User\GuestUser.csv‘
Step 3 – Let’s connect to our Azure tenant, so that we can invite our guest users for our default directory. Run the following PowerShell cmdlet . It will ask for our Azure tenant credential s shown in the following figure.
Connect-AzureAD -TenantId 'ee63368d-****-****-**c-**7e2c3******'
Step 4 – When inviting external user, we should send invitation with a valid message .e.g who is inviting for which reason. So that guest user will not avoid the invitation, if it is important and necessary. We can add message sing following powershell cmdlet as shown in the following figure.
$messageInfo = New-Object Microsoft.Open.MSGraph.Model.InvitedUserMessageInfo
$messageInfo.customizedMessageBody = "Hello. You are invited to the Manas Moharana's Azure Lab."
Step 5 – Now we are ready to invite all external/guest users using following powershell cmdlet as shown in the following figure.
foreach ($user in $GuestUsers)
New-AzureADMSInvitation -InvitedUserEmailAddress $user.EmailID -InvitedUserDisplayName $user.Name -InviteRedirectUrl https://myapps.microsoft.com -InvitedUserMessageInfo $messageInfo -SendInvitationMessage $true
Following figure showing, how our script is inviting external/guest users one by one.
- Verify the users were added to the directory – Now let’s verify, if the invited users added in our directory. As showing in the following figure all three users are added in the directory and the UserType is set to Guest for all external/guest users. We can also see the Source is set to Invited user.
Following figure showing a invitation mail sent to Guest User 3 with a valid message and a Accept Invitation link.
Now Guest User 3 has accepted the invitation and redeem the invitation as we can see in the following figure, the Source of the guest user is now changed to OTP
I hope, this article helps you to invite external/guest users in a bulk using powershell. With this article, I am concluding my B2B User section. In our next article we will come with a new topic.
As I am exploring the Azure Identity and Access Management (IAM) in a deep level. Please let me know if I missed anything important or if my understanding is not up to mark.
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more.
Thanks for reading 🙂