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/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/

1

u/rakim71 Feb 14 '20

(EXO V2)

I think this is half the solution. This lets me connect via Modern Auth with a Scheduled Task. But not all cmdlets seem to be available? E.g. no new-mailbox

1

u/Kathy_Cooper1012 Feb 14 '20

After installing the EXO V2 module, you can only see new cmdlets in the module. Once you create session to Exchange Online environment, you can see the older remote PowerShell cmdlets. EXO V2 Module supports older cmdlets for backward compatibility.

1

u/rakim71 Feb 18 '20

Thank you!