Office 365 – PowerShell Setup
Rate this post

PowerShell is the most important tool for Office 365 management and I find it helpful to have everything  just one click away. The following steps will give you a desktop shortcut to launch an Office 365 PowerShell session with the cmdlets loaded.

1. Install the Microsoft Online Service Sign-in Assistant and Azure Active Directory Module for Windows PowerShell available here

2. Save the following script to c:\o365.ps1:

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

If you don’t mind leaving your credentials saved in plain text on your computer, this alternative won’t prompt you to enter your credentials:

$User = "{}"
$Pass = ""
$Cred = New-Object System.Management.Automation.PsCredential($User,(ConvertTo-SecureString $Pass -AsPlainText -Force))
Import-Module MSOnline
Connect-MsolService -Credential $Cred
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session

3. Create a desktop shortcut with the target

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command "C:\o365.ps1"

4. Run the shortcut, enter your credentials (if you chose the secure option) and away you go!

Office 365

Leave a Reply

newest oldest most voted
Notify of

I got this tip from the Script Guy. Rather than store your password as plain text, you can instead use:

Get-Credential “” | Export-Clixml c:\example\Credential.xml

This exports an encrypted version of your password which is specific to your own device and profile.

I do have a question however, when you use the connect-MsolService cmdlet it connects you to your O365 tenant. Why is there a need after that to use the following cmdlet:

Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session


Chris K

Connect-MsolService will time out after 60 seconds if the host on which it is running has public IPv6 connectivity. The fix for this is to either reconfigure the host to preference IPv4 (using the DisabledComponents registry setting), or to add the following line to the HOSTS file on the host:

This should help save some people from wasting hours trying to work out why ConnectMsolService isn’t working for them.

Tony Hoyle

Thanks for this.. I just spent 2 hours trying to work out why Azure Active Directory Connect didn’t work. It’s a pretty poor show that a service launched less than a month ago isn’t compatible with ipv6.

Simon Waight

Thanks for the feedback Tony. You’re right – lack of IPv6 support in 2015’s certainly not great, but public cloud (regardless of provider) doesn’t yet deeply support it. Azure is working on adding it now, so hopefully over the next couple of years we’ll see everyone support it right through their stacks.

Follow Us!

Kloud Solutions Blog - Follow Us!