Inviting guest users to Microsoft 365 allows external users to collaborate with your organization. This guide will show you how to invite guest users individually and in bulk using Graph PowerShell.
Install-Module Microsoft.Graph -Scope CurrentUser
.Connect-MgGraph -Scopes "User.Invite.All"
To invite a single guest user and send an email invitation, use the following script:
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Invite.All"
# Define the guest user's details
$guestUserEmail = "guestuser@example.com" # Replace with the guest user's email address
$invitedUserDisplayName = "Guest User" # Replace with the guest user's display name
$invitedUserMessage = "You have been invited to join our organization. Please click the link to accept the invitation." # Customize this message as needed
# Create the invitation
$invitation = New-MgInvitation -InvitedUserEmailAddress $guestUserEmail -InvitedUserDisplayName $invitedUserDisplayName -InviteRedirectUrl "https://portal.office.com" -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"
}
For inviting multiple guest users, prepare a CSV file (guestUsers.csv) with the following format:
Email,DisplayName,Message
guestuser1@example.com,Guest User One,Welcome to our organization!
guestuser2@example.com,Guest User Two,Please join us for an exciting project!
Then use this script to send the invitations:
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Invite.All"
# Path to the CSV file
$csvPath = "path_to_your_csv_file.csv"
# Import the CSV file
$guestUsers = Import-Csv -Path $csvPath
foreach ($guestUser in $guestUsers) {
# Read guest user details from CSV
$guestUserEmail = $guestUser.Email
$invitedUserDisplayName = $guestUser.DisplayName
$invitedUserMessage = $guestUser.Message
# Create the invitation
$invitation = New-MgInvitation -InvitedUserEmailAddress $guestUserEmail -InvitedUserDisplayName $invitedUserDisplayName -InviteRedirectUrl "https://portal.office.com" -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"
}
}
If the email is invalid, the invitation will fail to send. If it’s a typo in a valid domain, the invitation may go to the wrong person. Always use -WhatIf to test before bulk invites.
Yes. You can re-run New-MgInvitation
with the same email address and add the -SendInvitationMessage
parameter to resend the invite.
You can run Get-MgUser -Filter "userType eq 'Guest'"
to list guest accounts. Accepted invitations will appear here with a valid UserPrincipalName.
Yes. The -InvitedUserMessageInfo
parameter lets you add a custom subject and body text, making the invite more personalized and informative.
Error | Cause | Solution |
---|---|---|
Insufficient Permissions | Insufficient privileges to complete the operation. | Ensure you have the necessary permissions. Connect to Microsoft Graph with the appropriate scopes: Connect-MgGraph -Scopes "User.Invite.All" |
Invalid Redirect URL | The redirect URL is not valid. | Verify that the InviteRedirectUrl is a valid URL. Use commonly accepted URLs like https://portal.office.com or your organization's specific URL. |
Invalid Email Address | Invalid email address. | Ensure the email addresses in your CSV file or script are correctly formatted and valid. |
CSV File Issues | Cannot process argument because the value of argument "path" is not valid. | Check the path to the CSV file and ensure it is correct. Also ensure the CSV file has the correct headers: Email, DisplayName, Message. |
Rate Limiting | Too many requests. | If you are inviting a large number of guests, you might hit the rate limit. Consider adding delays between requests or running the script in smaller batches. |
-WhatIf
for Safe Bulk Invites-WhatIf
parameter with New-MgInvitation
to simulate the operation first.
This helps prevent accidental invitations to emails with typos or invalid addresses.
-ResetRedemption
-ResetRedemption
flag.
This reactivates the invitation without creating duplicate guest accounts.
Using these simple scripts, you can efficiently manage guest user invitations in Microsoft 365, enhancing collaboration with external users. Whether you need to invite a single user or multiple users in bulk, Graph PowerShell provides a powerful and flexible solution.
For more PowerShell scripts and tips on managing Microsoft 365, visit M365Corner.com.
© m365corner.com. All Rights Reserved. Design by HTML Codex