Monday, October 1, 2012

Configuring Power Shell Access in Office 365

To use Powershell commands with Office 365 on a Windows 7 desktop you will need to firstly install the Microsoft Online Services Sign–in assistant. You can download this from:

 

32 bit version - http://g.microsoftonline.com/0BX00en/500

64 bit version - http://g.microsoftonline.com/0BX00en/501

 

Once you have downloaded file run it as an administrator.

 

clip_image001

 

Click the option to accept the license terms and press the Install button.

 

clip_image002

 

Allow the files to be installed.

 

clip_image003

 

Click the Finish button when complete.

 

To check that the assistant has been installed correctly navigate to the services on the machine via Start | Control Panel | Administrative Tools | Services.

 

clip_image004

 

Ensure that the service Microsoft Online Services Sign-in Assistant is present and started as shown above.

 

When complete close the services window.

 

Next, you will need to install the Microsoft Online Services Module for Windows Powershell. You can download this from:

 

32 bit - http://g.microsoftonline.com/0BD00en-US/565

64 bit - http://g.microsoftonline.com/0bd00en-us/557

 

Once downloaded, double click on the file to install.

 

clip_image005

 

Click Next to commence the installation.

 

clip_image006

 

Accept the license agreements and click Next to continue.

 

clip_image007

 

Select a location for the installation on your local machine and press Next to continue.

 

clip_image008

 

Press the Install button to commence the installation.

 

clip_image009

 

The files will now be installed to your local machine.

 

clip_image010

 

Press the Finish button to complete the installation process.

 

clip_image011

 

You should now see a new desktop icon like shown above – Microsoft Online Services Module for Windows PowerShell.

 

Double click the icon to launch Powershell.

 

clip_image012

 

You should now see a command prompt like shown above. This is different from the normal command prompt and can be denoted by the initials PS at the beginning of each line.

 

It is a good idea to alter the default execution policy of PowerShell on your system via the command:

 

Set-executionpolicy –remotesigned

 

If you don’t do this you may see an error like:

 

clip_image013

 

In this case set the section policy as shown above and re-run the powershell command that generated the issue.

 

At the command prompt type the following lines followed by the ENTER key.

 

import-module msonline

 

This will load the Microsoft Online Powershell commandlets into the environment so they can be used. It is normally already loaded when you run this, however it is good practice to ensure that it is loaded in case you ever launch just the standard Powershell environment.

 

clip_image014

 

You next need to capture the credential with which you wish to login to the Microsoft Online environment with. To do this enter the following command to assign the credentials to a variable $cred.

 

$cred=get-credential

 

This command will pop up the credential request window you see shown above. You need to enter the login to the Office 365 environment from which you wish to run these command. This will generally be an administrator.

 

Use the following command to connect to the Microsoft Online Service

 

connect-msolservice –credential $cred

 

Once these command are complete you are ready to use Powershell with the Office 365 environment you have logged into.

 

clip_image015

 

The following command will display a list of all the users configured in the Office 365 environment and the expiry status of their password:

 

get-msoluser –all | format-table userprincipalname, passwordneverexpires

 

If you need to work with Exchange Online then you will need to run the following commands to establish a connection with those services directly:

 

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection

Import-PSSession $Session

 

Once you do this you should see a number of modules loading

 

clip_image016

 

With the connection to Exchange online now established you can run commands like

 

Add-mailboxpermissions