Office 365 PowerShell connection script

If you working with Office 365 PowerShell on daily basis, you may find that it is taking too much time to connect your Office 365 console, especially if you working with multiple tenants. You have to note usernames, passwords for all of the tenants and copy/paste them every time you want to make connection. Below you will find description, how to make it “single command” task.

Because that script will give access to your tenant without typing any username/password, I would suggest that you should not implement that on any public machine. Make sure that you are only person who can execute connection script.

OK, let’s start.

First of all we need to create addition file where encrypted tenant’s password will be stored. As an example create directory “O365Connections” on your C: drive and then create folder “keys” in it.

Start PowerShell prompt and type following command:

Read-Host -Prompt "Enter your tenant password" -AsSecureString | ConvertFrom-SecureString | Out-File "C:\O365Connections\keys\tenant1.key"

Continue reading