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 https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Connect-MsolService -Credential $LiveCred