How to Fix PowerShell Script from Basic Auth to Modern Auth

KeithVanEaton-0729 1 Reputation point
2022-09-12T18:55:50.323+00:00

Greetings,

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 script 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 smtp.office365.com -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!

Windows for business Windows Server User experience PowerShell
Microsoft Security Microsoft Authenticator
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Dillon Silzer 57,826 Reputation points Volunteer Moderator
    2022-09-12T20:24:17.763+00:00

    Hi @KeithVanEaton-0729

    Here is a nice easy video for setting up authentication via certificate (so you can automate your PowerShell script unattended):

    How to setup ExchangeOnlineManagement for unattended scripting using a certificate (by TechSnips)

    https://www.youtube.com/watch?v=GyF8HV_35GA

    ----------------------------------------

    If this is helpful please accept answer.

    1 person found this answer helpful.

  2. KeithVanEaton-0729 1 Reputation point
    2022-09-21T22:21:08.577+00:00

    Thanks @Dillon Silzer for your suggestions, the fix eventually came down to this:

    from ******@place.com 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'  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.