Adding Guest Users in O365 Using PowerShell

Adding guest users manually can be tedious if you have many invites. Using PowerShell automates this process efficiently.


Step 1: Run PowerShell as Administrator


Step 2: Install the Microsoft Graph Module

Note: The AzureAD module is older and deprecated. Microsoft Graph is the modern alternative.

Install-Module Microsoft.Graph -Scope CurrentUser


Step 3: Connect to Microsoft Graph

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

Login with a Global Admin or User Administrator account.

⚠️ The scope User.ReadWrite.All is a permission, not your email.


Step 4: Prepare Your CSV File

Create a CSV file named Guests.csv with the following format:

FirstName,LastName,Email
John,Doe,john.doe@example.com
Jane,Smith,jane.smith@example.com

Save it somewhere easy to access, e.g., C:\\Path\\To\\Guests.csv.


Step 5: Import CSV and Create Guest Users

# Import CSV
$guests = Import-Csv "C:\\Path\\To\\Guests.csv"

foreach ($guest in $guests) {
    $displayName = "$($guest.FirstName) $($guest.LastName)"
    $email = $guest.Email

    # Create guest user invitation
    New-MgInvitation -InvitedUserEmailAddress $email `
                     -InviteRedirectUrl "<https://portal.office.com>" `
                     -InvitedUserDisplayName $displayName `
                     -SendInvitationMessage:$true
}