Invite guest users with PowerShell using a custom email template

Invite guest users with PowerShell using a custom email template

There are many ways to invite guest users to your Azure Active Directory. For example directly from the Azure Portal or by adding a guest to Microsoft Teams, if you have guest access enabled.

When you invite a new guest user directly from the Azure Portal, the invitee will receive an email invitation that looks like this:

Most of your users probably don’t even know what Azure Active Directory is. It could be that you are trying to educate your end users about email safety. To them, these emails seem ‘phishy’.

As an organization, you may want to consider inviting guests using a company branded email template. Sounds nice? Here’s how!

How to

  1. Download the New-CustomAzureADMSInvitation.ps1 script from the TechNet Gallery;
  2. Make sure you have the AzureAD module installed;
  3. Modify the $MailMessageProperties configuration to your needs;
    $MailMessageProperties = @{
        To         = $InvitedUserEmailAddress
        From       = "Jane Doe <>"
        Subject    = "You're invited to the $($AzureADTenantDetail.DisplayName) organization"
        SmtpServer = ""
        Credential = $Credential
        Port       = 587
  4. Customize the HTML email template specified in the $MailBody variable;
    Note: The script on TechNet contains a basic HTML template which you are free to customize.

    $MailBody = @" 
            <table align="center" style="width:600px;"> 
                <a href="$($AzureADMSInvitation.InviteRedeemUrl)">Click here to accept the invitation</a>. 
  5. Now you can run the script to invite guests to your Azure Active Directory!
    New-CustomAzureADMSInvitation.ps1 -InvitedUserDisplayName "John Doe" `
        -InvitedUserEmailAddress "" `
        -InviteRedirectUrl "" `
        -InviteMessage "Are you coming to my tea party?"


That’s it! You are now sending invites with PowerShell to external guest users using a custom email template. If you are using the basic HTML template provided in the script, the output will result in something like this:

Leave a Reply

Your email address will not be published. Required fields are marked *