Bulk Invite Entra ID Guest Users Using PowerShell

Inviting external users (guests) into Microsoft 365 one-by-one can be time-consuming—especially when you’re onboarding vendors, partners, clients, or contractors in bulk.

In this guide, you’ll learn how to bulk invite Microsoft 365 guest users using Microsoft Graph PowerShell, using a CSV input file and exporting a clean results report after execution.

🚀 Community Edition Released!

Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.

Sample CSV File Format (GuestUsers.csv)

Create a CSV file with the following headers:

DisplayName,EmailAddress
John Vendor,john.vendor@externaldomain.com
Sarah Partner,sarah.partner@partnerdomain.com
Adam Contractor,adam.contractor@contosoext.com
                            

✅ Make sure the column names match exactly: DisplayName and EmailAddress

Script

# ----------------------------- 
# Bulk Invite Guest Users (Graph PowerShell)
# -----------------------------

# Install module if needed:
# Install-Module Microsoft.Graph -Scope CurrentUser

Import-Module Microsoft.Graph.Identity.SignIns

# Connect to Graph (you must be a tenant admin to invite guests)
Connect-MgGraph -Scopes "User.Invite.All"

# Path to CSV
$CsvPath = "D:\test_data\guestusers-test-data\GuestUsers.csv"

# Import guest list
$GuestUsers = Import-Csv $CsvPath

# Output results
$Results = @()

foreach ($Guest in $GuestUsers) {

    $DisplayName  = $Guest.DisplayName
    $EmailAddress = $Guest.EmailAddress

    Write-Host "Inviting: $DisplayName <$EmailAddress>" -ForegroundColor Cyan

    try {
        $InvitationParams = @{
            InvitedUserDisplayName  = $DisplayName
            InvitedUserEmailAddress = $EmailAddress
            InviteRedirectUrl       = "https://myapps.microsoft.com"
            SendInvitationMessage   = $true
        }

        $InviteResult = New-MgInvitation -BodyParameter $InvitationParams

        $Results += [PSCustomObject]@{
            DisplayName            = $DisplayName
            EmailAddress           = $EmailAddress
            Status                 = "Invited"
            InvitedUserId          = $InviteResult.InvitedUser.Id
            InviteRedeemUrl        = $InviteResult.InviteRedeemUrl
            InvitationCreationTime = $InviteResult.CreatedDateTime
        }
    }
    catch {
        $Results += [PSCustomObject]@{
            DisplayName            = $DisplayName
            EmailAddress           = $EmailAddress
            Status                 = "Failed"
            InvitedUserId          = ""
            InviteRedeemUrl        = ""
            InvitationCreationTime = ""
            Error                  = $_.Exception.Message
        }

        Write-Host "Failed: $EmailAddress -> $($_.Exception.Message)" -ForegroundColor Red
    }
}

# Export results
$Results | Export-Csv ".\GuestInviteResults.csv" -NoTypeInformation

Write-Host "`nDone! Results saved to GuestInviteResults.csv" -ForegroundColor Green.
                            

How the Script Works

This script uses Microsoft Graph PowerShell to send guest invitations in bulk using a CSV input file.

  1. Imports the required Graph module
  2. Import-Module Microsoft.Graph.Identity.SignIns

    This loads the Graph module needed to run invitation-related commands.

  3. Connects to Microsoft Graph with required permission
  4. Connect-MgGraph -Scopes "User.Invite.All"

    The script connects using delegated permissions and requests the User.Invite.All scope, which is required to invite guest users.

  5. Loads guest users from the CSV file
  6. $GuestUsers = Import-Csv $CsvPath

    Each row in the CSV becomes one guest entry with:

    • DisplayName
    • EmailAddress
  7. Invites each guest using New-MgInvitation
  8. For each guest user, the script builds a hashtable:

    $InvitationParams = @{
        InvitedUserDisplayName  = $DisplayName
        InvitedUserEmailAddress = $EmailAddress
        InviteRedirectUrl       = "https://myapps.microsoft.com"
        SendInvitationMessage   = $true
    }
                                    

    Then it sends the invitation using:

    New-MgInvitation -BodyParameter $InvitationParams
  9. Captures success and failure results
  10. If the invite succeeds, the script stores details such as:

    • Status = Invited
    • InvitedUserId
    • InviteRedeemUrl
    • InvitationCreationTime

    If it fails, the script stores:

    • Status = Failed
    • Error message returned by Graph
  11. Exports the results to a CSV report
  12. $Results | Export-Csv ".\GuestInviteResults.csv" -NoTypeInformation

    At the end, you get a clean report file:
    ✅ GuestInviteResults.csv

Further Enhancements

Here are a few improvements you can add to make the script more powerful for real-world production use:

  1. Validate empty values before inviting
    Skip rows where DisplayName or EmailAddress is missing to avoid avoidable failures.
  2. Prevent duplicate invitations
    You can check if a guest already exists in Entra ID before inviting again.
    Example logic:
    • Search by mail address
    • If found, mark as “Already Exists” instead of inviting again
  3. Add custom invitation message
    You can customize the invitation message (branding + instructions) to reduce confusion for external users.
  4. Use different redirect URLs per guest type
    Instead of using a single redirect URL (https://myapps.microsoft.com), you can route users to:
    • A SharePoint onboarding page
    • A Teams welcome page
    • An internal access request portal
  5. Export results with timestamped file names
    This helps when you run the script frequently.
    Example idea:
    • GuestInviteResults-2026-01-31.csv

Possible Errors & Solutions

Below are common issues you may face while running this guest invitation script.

Error Cause Solution
Insufficient privileges to complete the operation Your account doesn’t have permission to invite guest users or the required scope wasn’t granted.
  • Ensure you signed in with an account that can invite guests
  • Reconnect using:
  • Connect-MgGraph -Scopes "User.Invite.All"
  • Make sure the permission is granted/consented successfully during login
InvalidAuthenticationToken / Access token is empty Graph authentication failed, or the token expired. Disconnect and reconnect:
Disconnect-MgGraph
Connect-MgGraph -Scopes "User.Invite.All"
New-MgInvitation : Resource not found This can happen if Graph modules aren’t loaded correctly, or if the environment is missing required dependencies.
  • Install Microsoft Graph module:
  • Install-Module Microsoft.Graph -Scope CurrentUser
  • Restart PowerShell and run the script again.
The term 'New-MgInvitation' is not recognized The required Graph module isn’t installed or not imported properly. Install and import the module:
Install-Module Microsoft.Graph -Scope CurrentUser
Import-Module Microsoft.Graph.Identity.SignIns
Import-Csv : Could not find file The CSV path in $CsvPath is incorrect. Verify the CSV file exists and update:
$CsvPath = "D:\test_data\guestusers-test-data\GuestUsers.csv"
One or more properties contains invalid values The email address format is invalid, or required fields are empty.
  • Ensure the CSV has valid values
  • Confirm headers match exactly:
    • DisplayName
    • EmailAddress

Conclusion

Bulk inviting guest users is one of the most common onboarding tasks for Microsoft 365 administrators—especially when working with external vendors and partner organizations.

With this Microsoft Graph PowerShell script, you can:

✅ Import guests from a CSV file
✅ Invite them automatically using Graph
✅ Capture success/failure results cleanly
✅ Export a detailed invitation report for tracking

Graph PowerShell Explorer Widget

20 Graph PowerShell cmdlets with easily accessible "working" examples.


Permission Required

Example:


                            


                            


                            

© Created and Maintained by LEARNIT WELL SOLUTIONS. All Rights Reserved.