Home

Setting Azure B2B Users as Members via the invitation

%3CLINGO-SUB%20id%3D%22lingo-sub-405014%22%20slang%3D%22en-US%22%3ESetting%20Azure%20B2B%20Users%20as%20Members%20via%20the%20invitation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-405014%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%20apologies%20if%20I%20haven't%20spotted%20this%20answer%20in%20another%20post.%20I%20am%20a%20PowerShell%20newbie%2C%20I%20am%20looking%20for%20a%20command%20to%20invite%20Azure%20B2B%20users%20and%20make%20them%20as%20Members.%20I%20have%20been%20using%20the%20command%26nbsp%3B%3CEM%3EGet-AzureADUser%20-SearchString%20userid%40domain.co.uk%20%7C%20Set-AzureADUser%20-UserType%20member%3C%2FEM%3E%20for%20individuals%2C%20but%20there%20is%20a%20need%20for%20me%20to%20bulk%20invite%20100%2B%20users%20and%20make%20them%20as%20members%2C%20any%20pointers%20will%20be%20very%20helpful.%20Many%20thanks%20in%20advance.%20Sabs%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-405014%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20AD%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20AD%20B2B%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-405182%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20Azure%20B2B%20Users%20as%20Members%20via%20the%20invitation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-405182%22%20slang%3D%22en-US%22%3EHad%20a%20look%20here%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fazuread%2Fnew-azureadmsinvitation%3Fview%3Dazureadps-2.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fazuread%2Fnew-azureadmsinvitation%3Fview%3Dazureadps-2.0%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EAdam%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-405587%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20Azure%20B2B%20Users%20as%20Members%20via%20the%20invitation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-405587%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F72542%22%20target%3D%22_blank%22%3E%40adam%20deltinger%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20quick%20response%2C%20I%20did%20look%20at%20that%20article%20before%20running%20my%20script%2C%20however%20it%20errored%20on%20InvitedUserType%20command.%20My%20script%20is%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%24invitations%20%3D%20import-csv%20c%3A%5Cscripts%5Cbulkinvite.csv%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%24messageInfo%20%3D%20New-Object%20Microsoft.Open.MSGraph.Model.InvitedUserMessageInfo%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%24messageInfo.customizedMessageBody%20%3D%20%22You%20are%20invited%20to%20the%20XXXXX%20organization.%22%3C%2FEM%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CEM%3Eforeach%20(%24email%20in%20%24invitations)%20%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%7BNew-AzureADMSInvitation%20%60%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E-InvitedUserEmailAddress%20%24email.InvitedUserEmailAddress%20%60%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E-InvitedUserDisplayName%20%24email.Name%20%60%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E-InviteRedirectUrl%20%3CA%20href%3D%22https%3A%2F%2Fmyapps.azure.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmyapps.azure.com%3C%2FA%3E%20%60%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E-InvitedUserMessageInfo%20%24messageInfo%20%60%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E-SendInvitationMessage%20%24false%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E-InvitedUserType%20%22Member%22%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20result%20is%20the%20User%20is%20invited%20as%20Guest%20and%20I%20get%20the%20following%20output%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3EInvitedUserType%20%3A%20Guest%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3EStatus%20%3A%20PendingAcceptance%3C%2FEM%3E%3C%2FP%3E%3CH6%20id%3D%22toc-hId-915936342%22%20id%3D%22toc-hId-915936342%22%20id%3D%22toc-hId-915936342%22%20id%3D%22toc-hId-915936342%22%3E%3CEM%3E-InvitedUserType%20%3A%20The%20term%20'-InvitedUserType'%20is%20not%20recognized%20as%20the%20name%20of%20a%20cmdlet%2C%20function%2C%20script%20file%2C%20or%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3Eoperable%20program.%20Check%20the%20spelling%20of%20the%20name%2C%20or%20if%20a%20path%20was%20included%2C%20verify%20that%20the%20path%20is%20correct%20and%20try%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3Eagain.%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3EAt%20line%3A8%20char%3A7%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%2B%20-InvitedUserType%20%22Member%22%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%2B%20~~~~~~~~~~~~~~~~%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%2B%20CategoryInfo%20%3A%20ObjectNotFound%3A%20(-InvitedUserType%3AString)%20%5B%5D%2C%20CommandNotFoundException%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%2B%20FullyQualifiedErrorId%20%3A%20CommandNotFoundException%3C%2FEM%3E%3C%2FH6%3E%3CP%3EThanks%20again%2C%3C%2FP%3E%3CP%3ESabs%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-763255%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20Azure%20B2B%20Users%20as%20Members%20via%20the%20invitation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-763255%22%20slang%3D%22en-US%22%3ETry%20changing%20%22-InvitedUserType%22%20to%20%22-UserType%22.%20This%20should%20work%20fine.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-485581%22%20slang%3D%22en-US%22%3ERe%3A%20Setting%20Azure%20B2B%20Users%20as%20Members%20via%20the%20invitation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-485581%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20is%26nbsp%3Ba%20snippet%26nbsp%3Bfrom%20a%20script%20I%20used%20to%20invite%20%26gt%3B%205000%20users%20to%20our%20tenant%20(and%20later%20to%20invite%20a%20few%20hundred%20more)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUp%20near%20the%20top%20of%20the%20script%2C%20I%20assign%20this%20(this%20is%20to%20make%20a%20member)%20-%20I%20don't%20think%20it%20is%20case%20sensitive%3C%2FP%3E%3CP%3E%24B2Busertype%3D%22member%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20code%20is%20used%20later%20(you%20can%20make%20an%20educated%20guess%20what%20the%20variables%20are%20from%20their%20names)%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EWatch%20for%20line%20wraps!%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%26nbsp%3Bif%20(%5Bstring%5D%3A%3Aisnullorempty(%24displayname))%20%7B%3CBR%20%2F%3E%26nbsp%3B%23%20if%20no%20displayname%20is%20specified%2C%20don't%20pass%20the%20parameter%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3Btry%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%24result%3DNew-AzureADMSInvitation%20-InvitedUserEmailAddress%20%24upn%20-InviteRedirectUrl%20%24url%20-SendInvitationMessage%20%24false%20-InvitedUserType%20%24B2Busertype%20-ea%20stop%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%7D%20catch%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%24goterr%3D1%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%7D%20%23%20end%20try%20catch%3CBR%20%2F%3E%26nbsp%3B%7D%20else%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3Btry%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%24result%3DNew-AzureADMSInvitation%20-InvitedUserEmailAddress%20%24upn%20-InviteRedirectUrl%20%24url%20-SendInvitationMessage%20%24false%20-InvitedUserType%20%24B2Busertype%20-InvitedUserDisplayName%20%24displayname%20-ea%20stop%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%7D%20catch%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%24goterr%3D1%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%7D%20%23%20end%20try%20catch%3CBR%20%2F%3E%26nbsp%3B%7D%20%23%20end%20if%20%5Bstring%5D%20null%20displayname%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
sabsync
New 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.
Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
50 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
32 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
15 Replies
Dev channel update to 80.0.355.1 is live
josh_bodner in Discussions on
67 Replies