How to get persistent login in PS ISE session

This should be easy for everyone here but given that I only use PS every few years, I need to get rebooted on authentication.

I am using PS to connect to Office 365 / Exchange Online. I have notes from the last time but they are obsolete as far as authentication goes what with a) our company has now turned on 2FA and b) the MSFT authentication has changed.

  • ultimately, what I want to do is to get a list for all mailboxes in our tenant and for each mailbox, has the user delegated viewing rights to other people; and output to a csv file

The first problem though is to authenticate to O365 and to to have this persist between commands; I get prompted for credentials, including 2FA to my phone, when I run a command such as this:

I tried this but then I seemed to get prompted for each subsequent command:


Does the authentication apply to the current PS session or does it have to get stuffed into a variable for use in other commands?

TL:DR It depends on how O365 is configured.

Ultimately accessing any O365 resource is done through an API behind the scenes and APIs are stateless. Meaning some form of authentication is passed for every call. Typically this is a token acquired by, in your case, the connect-exchangeonline. Depending on how O365 (most likely a conditional access policy) is configured you could be required to authenticate each time.

Usually you authenticate your session/console and it will persist until you close this particular session/console. At least that’s how it works for me. ¯\_(ツ)_/¯

1 Like

Maybe you could confirm this, it seems that for the next 2 commands I have to authenticate once for each command:


And on the second command, it gives you this screen and it seemed to work best if I choose “choose another account” and put in my Office 365 mailbox address again; can you also confirm that?


It seems to “attach” the authentication token to each “connect” - there probably is one object for the MS online session and another authentication token attached to the exchange online session

Finally, do you find that you have to start ISE in admin mode or does it matter? Sometimes it seems to choke if I start it without being in admin mode.

I can’t. :man_shrugging:t3: Usually I only connect to one service at a time. And as long as this one session lasts I don’t have to authenticate again.

If I got it right you may update to a more current module anyway

These are completely different environments. It’s akin to saying “why do I have to sign in to gmail after I sign into hotmail.” However, after logging into both of those they should both stay signed in for the duration of the powershell session (within reason) as Olaf stated.

1 Like

It seemed to last this time around. I just connected to both and they continued to work…who knows why I had trouble before! Thanks for the help all.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.