How to Fix PowerShell Script from Basic Auth to Modern Auth

Copper Contributor


I am not a manager of an Exchange Server, I'm just a guy whose PowerShell script used to work until 9/1/2022. Now it doesn't work per the Exchange Basic Auth to Modern Auth update.


I have a PowerShell script that, after pinging a server address, uses Basic Auth to send an automated email via Task Scheduler. Microsoft has deprecated Basic Auth in Exchange Online in favor of Modern Auth, but I do not see clear directions for updating a PowerShell script to use Modern Auth.

This is an example of the Basic Auth that I need to convert to Modern Auth:

$secpasswd = ConvertTo-SecureString “password” -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential (“alias AT place dot com”, $secpasswd)
Send-MailMessage -SmtpServer -Port 587 -From alias AT place dot com -To anotheralias AT place dot com -Subject test -Body test -Credential $mycreds -UseSsl"

I cannot find ANY information on how to update this script to use the Modern Auth method.


Can someone please point me to an example of a PS script with email Modern Auth being used in a similar script or share the specific code for what I need to do to update and run the above script?

Many Thanks!

1 Reply
The fix eventually came down to this:

- from email address removed for privacy reasons I had to drop the '' and just keep the alias
- with -SmtpServer I had to drop '' and replace with '[uni].edu'