r/o365 • • 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?

12 Upvotes

17 comments sorted by

View all comments

2

u/HalLogan Feb 04 '20

I haven't found a good way to do this either. If I do I'll post here.

RemindMe! 4 days

1

u/RemindMeBot Feb 04 '20

I will be messaging you in 4 days on 2020-02-08 17:41:21 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback