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 https://ps.outlook.com/powershell/ -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 = "{user@domain.com.au}"
$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 https://ps.outlook.com/powershell/ -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!

Category:
Office 365
Tags:

Join the conversation! 5 Comments

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

    Get-Credential “example@yourdomain.com” | 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 https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection
    Import-PSSession $Session

    Thanks!

    Reply
    • Connect-MsolService is required to establish a session with Azure, to enable the use of Azure cmdlets (Set-MsolUser etc.). The commands you mentioned set up the Exchange Online management session only.

      Reply
  2. 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:

    157.55.227.200 provisioningapi.microsoftonline.com

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

    Reply
    • 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.

      Reply
      • 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.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: