New-MgInvitation

What is New-MgInvitation?

The New-MgInvitation cmdlet in Microsoft Graph PowerShell is used to invite external users (guests) to join a Microsoft 365 tenant. This is commonly used in B2B collaboration scenarios, where organizations grant partners, vendors, or clients secure access to resources such as Teams, SharePoint, or other M365 apps.


Why Use New-MgInvitation?

Using New-MgInvitation helps administrators:

  • Onboard external partners and contractors quickly.
  • Automate bulk guest user creation from CSV files.
  • Send customized welcome messages with invite links.
  • Standardize external collaboration policies across Microsoft 365.

This cmdlet simplifies and automates a process that would otherwise require manual work in the Azure AD or Microsoft Entra admin portal.


Prerequisites

Before inviting guest users, connect to Microsoft Graph with appropriate permissions:

Connect-MgGraph -Scopes "User.Invite.All"

How to Use New-MgInvitation?

Syntax (essential parameters):

New-MgInvitation -InvitedUserEmailAddress "henry@contoso.com" `
-InvitedUserDisplayName "Henry Adams" `
-InviteRedirectUrl "https://portal.office.com" `
-SendInvitationMessage `
-InvitedUserMessageInfo @{customizedMessageBody = "Welcome to our organization!"}
                                        

This cmdlet requires the user’s email address, display name, and a redirect URL, with optional customized messages.


New-MgInvitation Examples

  • Example 1: Invite a Single Guest User
  • New-MgInvitation -InvitedUserEmailAddress "henry@contoso.com" `
    -InvitedUserDisplayName "Henry Adams" `
    -InviteRedirectUrl "https://portal.office.com" `
    -SendInvitationMessage `
    -InvitedUserMessageInfo @{customizedMessageBody = "Welcome to our organization!"}
                                                

    Verify the invitation using:

    Get-MgUser -Filter "Mail eq 'henry@contoso.com'"
  • Example 2: Bulk Guest User Creation via CSV
  • CSV file format:

    Email,DisplayName,Message
    henry@contoso.com,Henry Adams,Welcome to Contoso!
    julia@fabrikam.com,Julia Smith,Please review the documents shared with you.
                                                

    PowerShell script:

    # 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) {
            $guestUserEmail = $guestUser.Email
        $invitedUserDisplayName = $guestUser.DisplayName
        $invitedUserMessage = $guestUser.Message
                                                    
        $invitation = New-MgInvitation -InvitedUserEmailAddress $guestUserEmail `
                                       -InvitedUserDisplayName $invitedUserDisplayName `
                                       -InviteRedirectUrl "https://portal.office.com" `
                                       -SendInvitationMessage `
                                       -InvitedUserMessageInfo @{customizedMessageBody = $invitedUserMessage}
                                                    
        if ($invitation.Status -eq "PendingAcceptance") {
            Write-Output "Invitation sent successfully to $guestUserEmail"
        } else {
            Write-Output "Failed to send invitation to $guestUserEmail"
        }
    }
                                                

    This approach is ideal for bulk onboarding of guest users into Microsoft 365.


Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.

Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.

© Your Site Name. All Rights Reserved. Design by HTML Codex