I spend a lot of my time logging in and out of various tenants using PowerShell. Some tenants require Multi Factor Authentication (MFA), others don’t. Sometimes I need to just use SharePoint Online or maybe Exchange and Teams.
Already having all the appropriate online services connection scripts in my Github repo here:
https://github.com/directorcia/Office365
I wanted a way to make it easy for me to login to any tenant, MFA or not, as well as an service, or combination of services. Thus my latest script at:
https://github.com/directorcia/Office365/blob/master/o365-connect-bulk.ps1
provides a neat solution I believe.
They way it works is that:
1. You need to copy all the files from my Github repo to a directory on your local environment.
2. Execute the o365-connect-bulk.ps1 script where all the scripts are with following command line options:
-mfa if MFA required for login
-std if Microsoft Online connect required
-aad if Azure AD connect required
-exo if Exchange Online connect required
-s4b if Skype for Business Online connect required
-sac if Security and Compliance Center connect required
-spo if SharePoint Online connect required
-tms if Microsoft Teams connect required
-aadrm if Azure AD Rights Management connect required
You can combine some or all of these onto the command line like so:
.\o365-connect-bulk.ps1 –mfa –exo –tms
which will do a login with MFA for Exchange Online and Microsoft Teams. Or:
.\o365-connect-bulk.ps1 –std –spo
which will login with no MFA to Microsoft Online and SharePoint Online.
The way that I use scripts is to break them down into small scripts. I don’t like the idea of large ‘mega’ scripts that do everything because they are harder to maintain and when they break they are harder to debug. This way, o365-connect-bulk.ps1 relies in the other stand alone scripts in the same directory which it calls as needed.
The down side to this approach is that you may need to login to the tenant multiple times as each independent script runs. That is only initially and a small price to pay for the added flexibility and functionality I would suggest.
If need to login to many different tenants and services throughout the day then this bulk connection script should help you.