Insights Create a Shortcut to Remote PowerShell for Office 365 and Exchange Online

Create a Shortcut to Remote PowerShell for Office 365 and Exchange Online

Office 365 includes support for remote PowerShell for the management of users, the tenant itself, and Exchange Online (Lync Online PowerShell support should be coming soon).  PowerShell support makes administration of Office 365 much easier since a great deal of functionality is hidden in the Office 365 portal, but is exposed in PowerShell.  PowerShell’s ability to perform bulk actions is also a big reason to get familiar with remote PowerShell in Office 365.  The problem is that connecting to remote PowerShell can sometimes require you to remember somewhat long and specific commands.  If you are anything like me then you have been forced to consult your notes for the commands countless times.  With a little basic setup this shortcut should make connecting to Office 365 with PowerShell much easier. These first steps are in case you have not installed the Windows Azure Active Directory Module for Windows PowerShell.  If you already have it installed then skip to the next section.

Select Set up at the top of the Users menu in the Office 365 portal.[/caption]

Under Step 3 select the appropriate version of the Windows Azure Active Directory Module for Windows PowerShell and click Download:

  • Click Next on the Welcome screen and accept the License terms.  Click through the prompts until the tool is installed.

At this point we are ready to create the short script that will be used in our shortcut.

  • Open PowerShell ISE to create a new script or create a new text file and enter these lines:
    • $cred = Get-Credential
    • Import-Module MSOnline
    • Connect-MsolService -Credential $cred
    • $s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection
    • $importresults = Import-PSSession $s
  • It will look like this:
  • Save the file as something like Connect-Office365.ps1.  If you entered the lines in a text file save the file and then change the file type to .ps1.
  • Next create a new shortcut wherever you would like.  In the location field type powershell.exe
  • lick Next, choose a name for your shortcut, and click Finish.
  • Right click the shortcut and choose Properties.  The Target field will contain this information: C:WindowsSystem32WindowsPowerShellv1.0powershell.exe
  • After that information type in -noexit -File “C:UsersmichaelSkyDriveConnect-Office365.ps1” where the path after -File is the location of your PowerShell script.  The entire contents of the Target field should resemble C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -noexit -File “C:UsersmichaelSkyDriveConnect-Office365.ps1”
  • Click Ok to exit out of the shortcut’s properties.

Your shortcut should now be working.  Double click it and it will prompt you for credentials.  Enter your Office 365 administrator credentials and it will load the Msol cmdlets and the Exchange Online cmdlets.

Both Msol and Exchange Online commands work.[/caption] I chose not to explore embedding credentials in the script because I work with different customer Office 365 tenants quite often and benefit from choosing which credentials to enter, but it should be possible to alter the script so that it logs in without the prompt.  I would also recommend pinning the shortcut to your Start Menu or Start Screen so you have quick access to it.