Super-Simple Script for connecting to Office 365 via PowerShell

One of the repetitive menial tasks of being an Office 365 consultant is connecting to the remote PowerShell session for different clients.  I thought I’d share a little script I wrote to help simplify this task for me.  It’s not ground-breaking code but I find it useful as have some of my clients.

The script prompts you for your credentials, establishes the session and then also imports the MSOnline module for running those related commands.

Simply save the code snippit below to a new text file (I call mine Connect-Office365.ps1) and place it in your home directory so it’s quickly available when you launch PowerShell.

$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Import-Module MSOnline
Connect-MsolService -Credential $LiveCred


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s