Use this PowerShell profile to connect and use Exchange Online, MS Online, AD, and DirSync cmdlets



If you're working with Exchange Online and other Microsoft Online services, chances are you probably use the same set of cmdlets over and over again. To minimze the amount of repetitive typing required just to get started, here's the PowerShell profile script that i use that will do all the prep work for you:

  1. Switch to your preferred script directory (don't forget to modify the path)
  2. Store your MS Online credentials (in $OnlineCred variable)
  3. Create a PowerShell session to Exchange Online
  4. Check for presence of msonline module and load it, if present (or display a message if it's not)
  5. Check for presence of MS Online Directory Synchronization snap-in and load it, if present (or display a message if it's not)
  6. Check for presence of Active Directory module and load it, if present (or display a message if it's not)
  7. Change the title of the PowerShell window to show your MS Online user id and also which modules have been loaded (Microsoft.Exchange, msonline, dirsync, active directory)

Download the profile script from attachments area

To use the profile, fire up Powershell, then run these commands (don't overwrite, unintentionally, an existing profile by running notepad $profile - if a file opens up, make sure there's nothing there you want):

new-item -type file -path $profile -force

notepad $profile

Open the downloaded profile.txt, copy and paste its contents into the profile script you just opened - modify the script start directory (2nd line) first, though (or comment it out). Save the file and exit Powershell.

When you start it up again (make sure to run it as Administrator), it'll run all the commands in the script and get your work environment ready for MS Online administration tasks!

Note that you may get an execution policy error:


Execute the following command:

set-executionpolicy remotesigned

...and confirm when prompted. Restart powershell (again, as Administrator), and the script will execute. Submit a helpdesk ticket if you need any help!

Have more questions? Submit a request


Powered by Zendesk