Office 365 Functions in Your PowerShell Profile

PowerShell is easily my favorite tool Microsoft provides system administrators with. I love automation because I am lazy and dont want to have to do simple tasks manually through a GUI. This is the shared feeling by most users of PowerShell.

One of the great things about PowerShell is its integration with the entire Microsoft Ecosystem. Microsoft themselves provide modules for nearly all their technologies, and Office 365 is one of them. As I’ve had a particular focus on the Microsoft cloud offerings, this is incredibly important to me.

The Commands To Connect to the Cloud

First, the prerequisites:

Lots of things to install, but if you are constantly in Office 365, it is an easy thing to install them once and be done. Now, there are just three lines you have to run in order to connect!

Boom, connected to your Office 365 Azure Active Directory. Young naive me would copy each of those three lines individually each time I wanted to make a connection to a particular Azure Active Directory (which I was doing frequently). So, I needed to make it easier.

PowerShell Profile!

I just needed to make a function out of those three lines, and with one simple command, I was connected to Azure Active Directory in Office 365. So, I setup my PowerShell Profile and made a function out of it.

Simple, my single command would ask for my credentials and would connect automatically for me.

One Step Further for Exchange

However, I would primarily connect to Office 365 through PowerShell for Exchange related tasks, so I wanted to make that connection at the same time. So, I edited my function (and renamed it) so it would make both those connections in the same session.

And that is it! I was able to run my single command and have the functionality I needed. You could continue this progression with add the commands for connecting to SharePoint Online and Skype for Business Online, but I was content with Exchange and Azure AD.

Leave a Reply

Your email address will not be published. Required fields are marked *