As I have started to spend more and more time using PowerShell connecting to all the necessary services when I needed was beginning to be a drag. Also, every time I wrote a script I added a section for connecting to the required services. After finding some spare time one long weekend, I created a modular script and set my self a few rules.

  1. I must be able to call this from another script.
  2. Must support MFA
  3. I should only enter data once where I can
  4. If something goes wrong, I want the script to stop.

    This is important as I haven’t built in error correction ready for this script in my existing scripts. When I have fixed this up, I will take the pauses out.

  5. It should not repeat its self

    Failed a little bit on this one as final connection is just a bunch of ifs.

This went quite well for Version 1.0, there are a few things to improve, but I wanted to get some to build on.

Currently supported systems

  • Exchange Online,
  • MSOL
  • Azure AD
  • On-Premise Exchange
  • On Premise Lync
  • Skype for Business Online
  • Teams

Prerequisites

First run

Edit any values in the get-custom section at the top of the script to your environment requirements. If you don’t need a part you can delete it or just leave it.

The Code

As this is my first more extensive project that would fill up a blog post I have hosted the file on my GitHub public repo. I am happy for any feedback; this is the first time I have looked at doing a more fully formed script using functions.

Examples

#This will connect to Exchange Online, On-Premise Exchange and Teams, prompting for an email and on Prem credentials  
Connect-toServices.ps1 -ExchangeOnline -onpremExchange -Teams