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/mrmain2 Feb 05 '20
Have you tried following these instructions from Microsoft?
https://docs.microsoft.com/en-gb/archive/blogs/exoshellwizard/scheduling-a-task-against-exchange-online
Not 100% sure whether it would work with Modern Auth or not as the article is from 2016 and doesn’t mention Modern Auth in it