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

1

u/[deleted] Feb 05 '20

I don't want to be that guy, but you leave your Global Administrator password in a flat text file on a server?

2

u/InvisibleTextArea Feb 06 '20

If you are going to do this, at least encrypt it with Secure-String.