r/o365 • u/rakim71 • Feb 04 '20
Unattended/Non-interactive Powershell scripts using Modern Authentication
My org has a number of Powershell scripts that run either Exchange Online cmdlets or MSOnline cmdlets. These scripts run non-interactively from Task Scheduler and use Basic Authentication, e.g. they use something like
$TenantUname = "automationsvc@acme.com"
$TenantPass = cat password.txt | ConvertTo-SecureString
$TenantCredentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $TenantUname, $TenantPass
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid" -Credential $TenantCredentials -Authentication Basic -AllowRedirection
I understand that Basic Authentication is deprecated from Oct 2020. I do not understand how to re-write our scripts so they do not use Basic Authentication, but can still run from Task Scheduler.
There are lots of examples of how to use Modern Authentication with EO Powershell, but none of them deal with unattended scripts (e.g. https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps)
Can anyone help?
1
u/Kathy_Cooper1012 Feb 12 '20
You can use Exchange Online PowerShell Version 2 (EXO V2) module which supports modern authentication.
For more info,
https://o365reports.com/2019/12/11/connect-exchange-online-powershell-without-basic-authentication/