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:
Connect-ExchangeOnline
Does the authentication apply to the current PS session or does it have to get stuffed into a variable for use in other commands?
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. ÂŻ\_(ă)_/ÂŻ
Maybe you could confirm this, it seems that for the next 2 commands I have to authenticate once for each command:
Connect-MSOLService Connect-ExchangeOnline
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.
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.