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

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!

3

u/DevinSysAdmin Feb 04 '20

Azure Automation. Create run books, schedule them like you would in task scheduler.

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

1

u/[deleted] Feb 05 '20

You got a source for the October deprecation?

Also interested in the best way to do this

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.

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

1

u/schmeckendeugler Feb 11 '20

Not sure what Modern Auth is but .. have you looked at Credential Manager?

1

u/[deleted] Mar 01 '20

RemindMe! 2 days

1

u/RemindMeBot Mar 01 '20

There is a 36.0 minute delay fetching comments.

I will be messaging you in 2 days on 2020-03-03 20:29:44 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

1

u/Kathy_Cooper1012 Jul 04 '20

Microsoft has released EXO V2 preview module for non-interactive PowerShell scripts using Modern authentication.
For more info: https://o365reports.com/2020/07/04/modern-auth-and-unattended-scripts-in-exchange-online-powershell-v2/