Search code examples
powershellexchange-serverpowershell-3.0

How to Fix PowerShell Script from Basic Auth to Modern Auth


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.

$secpasswd = ConvertTo-SecureString “password” -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential (“[email protected]”, $secpasswd)
Send-MailMessage -SmtpServer smtp.office365.com -Port 587 -From [email protected] -To [email protected] -Subject test -Body test -Credential $mycreds -UseSsl"

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

Many Thanks!


Solution

  • Thanks @postanote for your suggestions, the fix eventually came down to this:

    • from [email protected] I had to drop the 'place.com' and just keep the alias
    • with -SmtpServer smtp.office365.com I had to drop 'office365.com' and replace with '[uni].edu'