Setting Azure B2B Users as Members via the invitation

Copper Contributor

Hi All, apologies if I haven't spotted this answer in another post. I am a PowerShell newbie, I am looking for a command to invite Azure B2B users and make them as Members. I have been using the command Get-AzureADUser -SearchString userid@domain.co.uk | Set-AzureADUser -UserType member for individuals, but there is a need for me to bulk invite 100+ users and make them as members, any pointers will be very helpful. Many thanks in advance. Sabs

4 Replies

Hi @adam deltinger 

 

Thanks for the quick response, I did look at that article before running my script, however it errored on InvitedUserType command. My script is:

 

$invitations = import-csv c:\scripts\bulkinvite.csv
$messageInfo = New-Object Microsoft.Open.MSGraph.Model.InvitedUserMessageInfo
$messageInfo.customizedMessageBody = "You are invited to the XXXXX organization."

foreach ($email in $invitations)
{New-AzureADMSInvitation `
-InvitedUserEmailAddress $email.InvitedUserEmailAddress `
-InvitedUserDisplayName $email.Name `
-InviteRedirectUrl https://myapps.azure.com `
-InvitedUserMessageInfo $messageInfo `
-SendInvitationMessage $false
-InvitedUserType "Member"
}

 

The result is the User is invited as Guest and I get the following output: 

 

InvitedUserType : Guest
Status : PendingAcceptance

-InvitedUserType : The term '-InvitedUserType' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:8 char:7
+ -InvitedUserType "Member"
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (-InvitedUserType:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Thanks again,

Sabs

 

This is a snippet from a script I used to invite > 5000 users to our tenant (and later to invite a few hundred more)

 

Up near the top of the script, I assign this (this is to make a member) - I don't think it is case sensitive

$B2Busertype="member"

 

This code is used later (you can make an educated guess what the variables are from their names)


Watch for line wraps!


 if ([string]::isnullorempty($displayname)) {
 # if no displayname is specified, don't pass the parameter
  try {
   $result=New-AzureADMSInvitation -InvitedUserEmailAddress $upn -InviteRedirectUrl $url -SendInvitationMessage $false -InvitedUserType $B2Busertype -ea stop
  } catch {
   $goterr=1
  } # end try catch
 } else {
  try {

   $result=New-AzureADMSInvitation -InvitedUserEmailAddress $upn -InviteRedirectUrl $url -SendInvitationMessage $false -InvitedUserType $B2Busertype -InvitedUserDisplayName $displayname -ea stop
  } catch {
   $goterr=1
  } # end try catch
 } # end if [string] null displayname

 

Try changing "-InvitedUserType" to "-UserType". This should work fine.