Forum Discussion
Tim_Opie
Aug 09, 2024Copper Contributor
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...
Tim_Opie
Aug 11, 2024Copper 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_Opie
Aug 12, 2024Copper 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"
}
}
- LainRobertsonAug 12, 2024Silver Contributor
I made a mistake with the HashTable-only example (I was careless and copied the typed HashTable). It should have looked like this
$InvitedUserMessageInfo = @{ CustomizedMessageBody = "Welcome!"; }Cheers,
Lain