Secrets from the field – Windows PowerShell Part 1 – Streamline PowerShell Setup

Website relaunched and updated

If you are like me you find yourself using PowerShell to administer your Office 365 Exchange Online environment. There are several articles that give you the instructions for how to connect remote PowerShell to your Office 365 tenant. They all start with the steps like this:

1. Install the Microsoft Online Services Sign-in Assistant and the Azure Active Directory PowerShell modules
2. Launch PowerShell and run the following commands to connect
$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

I get tired of running these lines every time I need to connect and run a command or pull a piece of information for a tenant. I found a great blog post by David Ross with instructions on how to setup an icon your desktop to launch and connect remote PowerShell to your Office 365 tenant automatically. Below are the steps to set this up for yourself. This is a true time saving setup.

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

2. Save the following lines below in a text file as a 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

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 and get connected!

One optional piece I like to do is to right-click on the icon and choose properties. On the Shortcut tab click the Advanced button and enable the Run as administrator option. Now no more right-clicks when launching the icon.

Image

About Larry Taylor

Innovative helps you balance your business requirements, service levels, staff and infrastructure to make your IT as effective as possible. Larry Taylor is a Senior Solutions Consultant at Innovative with a focus on Microsoft technologies. Since 2002, Larry has been recommending, deploying, and providing support for organizations to align technology solutions with their business needs.

Leave a Reply

Innovative Integration can help you optimize your IT infrastructure. Request a Consultation