Entra / Microsoft 365 · Exchange Online
Send welcome new user messages hve
The classic send new welcome messages reprised for Exchange Online High-Volume Email.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-ExchangeOnline -SkipLoadingCmdletHelp
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
param([int] $LookbackDays = 7)$CheckDate = [datetime]::UtcNow.AddDays(-$LookbackDays).ToString("s") + "Z"# Connect to Exchange Online$Modules = Get-Module | Select-Object -ExpandProperty NameIf ('ExchangeOnlineManagement' -notin $Modules) {Write-Host "Connecting to Exchange Online..."Connect-ExchangeOnline -SkipLoadingCmdletHelp}# Find mailboxes matching the search criteriaWrite-Host "Looking for recently created mailboxes..."[array]$Users = (Get-ExoMailbox -Filter "WhenMailboxCreated -gt '$CheckDate'" -RecipientTypeDetails UserMailbox `-ResultSize Unlimited -Properties WhenMailboxCreated | Select-Object WhenMailboxCreated, DisplayName, UserPrincipalName, PrimarySmtpAddress)IF (!$Users) {Write-Host "No new mailboxes found"Break}# Get the credentials for the HVE account we want to use$HVECredentials = Get-Credential -Message "Enter credentials for the HVE account" -UserName 'HVE1@office365itpros.com'# BCC address for each message - also used in the message content$BCCAddress = "Customer.Services@contoso.com"# Enforce TLS 1.2[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12ForEach ($User in $Users) {Write-Host ("Processing mailbox {0} created on {1}" -f $User.UserPrincipalName, $User.WhenMailboxCreated)# Set up message content$Content = "<h2>Welcome to Microsoft 365</h2><p>" +("<p>Dear {0},</p>" -f $User.displayName) +"<p>Welcome to Microsoft 365. Your mailbox is now ready for use. Please sign in to Outlook on the web at " +"<a href='https://outlook.office.com'>https://outlook.office.com</a> to access your email.</p>" +"<p>If you need help, please check the <a href='https://office365itpros.com/office-365-for-it-pros-faq/'>FAQ</a> or send email to the " +("<a href='mailto:{0}'>End User Support Desk</a>.</p>" -f $BCCAddress) +"<p>This email was sent using Exchange Online High-Volume Email<p>"$SendHVEMessageParams = @{From = 'HVE02@office365itpros.com'To = $User.PrimarySmtpAddressBcc = $BCCAddressSubject = "Welcome to Microsoft 365"Body = $ContentCredential = $HVECredentialsUseSsl = $trueSmtpServer = 'smtp-hve.office365.com'Port = 587BodyAsHtml = $True}Try {Send-MailMessage @SendHVEMessageParams -ErrorAction Stop} Catch {Write-Host ("Failed to send email to {0} with error {1}" -f $Recipient, $_.Exception.Message)}}
Parameters
ParameterDefaultNotes
-LookbackDays7How many days back to search for newly created mailboxes or recent activity.Attribution
Author
Office365itpros