Forum Discussion
B2B Invite error
Hi,
Have been trying to invite some external users using the https://learn.microsoft.com/en-us/entra/external-id/bulk-invite-powershell.
When trying to run this line
$messageInfo = New-Object Microsoft.Open.MSGraph.Model.InvitedUserMessageInfo
I get this error
New-Object: Cannot find type [Microsoft.Open.MSGraph.Model.InvitedUserMessageInfo]: verify that the assembly containing this type is loaded.
I have tried uninstalling and reinstalling the Microsoft.Graph module.
Any ideas what I am doing wrong?
Thanks
- LainRobertsonSilver Contributor
Hi, Tim.
Did you import the module first before calling New-Object?
Import-Module -Name Microsoft.Graph.Identity.SignIns;
Here's a couple of extra curiosities:
- Under the 2.21.1 modules, the [Microsoft.Graph.PowerShell.Models.MicrosoftGraphInvitation] type is missing from the Microsoft.Graph.Beta.Identity.SignIns module. However, it remains available in the Microsoft.Graph.Identity.SignIns module;
- Apparently, you can use a HashTable instead:
$InvitedUserMessageInfo = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphInvitation]@{ CustomizedMessageBody = "Welcome!"; } New-MgInvitation -InvitedUserDisplayName "{Name}" -InvitedUserEmailAddress "{Email_Address}" -InviteRedirectUrl "{URI}" -InvitedUserMessageInfo $InvitedUserMessageInfo;
I haven't tested the HashTable approach but may do so later - specifically with the beta module, given it currently lacks the formal type definition.
Cheers,
Lain
- Tim_OpieCopper Contributor
Ah right, thanks! I have tried loading the module, but I still get the same error.
I also tried the HashTable method you have suggested which technically worked (account was added as a B2B guest) but didn't send the invite to my test account, any suggestions why it might not?Appreciate the assistance!
Tim
- Tim_OpieCopper Contributor
Found another script which seems to get around that issue. Think I might have been using the wrong syntax for the account creation also haha. Used to work anyway. Cheers for the help!
# Connect to Microsoft Graph Connect-MgGraph -Scopes "User.Invite.All" # Path to the CSV file $csvPath = "C:/temp/file.csv" # Import the CSV file $guestUsers = Import-Csv -Path $csvPath $invitedUserMessage = "Welcome" foreach ($guestUser in $guestUsers) { # Read guest user details from CSV $guestUserEmail = $guestUser.Email $invitedUserDisplayName = $guestUser.DisplayName # Create the invitation $invitation = New-MgInvitation -InvitedUserEmailAddress $guestUserEmail -InvitedUserDisplayName $invitedUserDisplayName -InviteRedirectUrl "URL" -SendInvitationMessage -InvitedUserMessageInfo @{customizedMessageBody = $invitedUserMessage} # Output the result if ($invitation.Status -eq "PendingAcceptance") { Write-Output "Invitation sent successfully to $guestUserEmail" } else { Write-Output "Failed to send invitation to $guestUserEmail" } }