Using PowerShell against Office 365

As we know that in Office 365, users do not get the fully-polished feature rich Central Administration or Exchange Administration Center like your on-premises setup. Therefore, there are certain tasks that will be missing from the features that Microsoft have provided to you as a Office 365 subscriber.

However, worry not! Microsoft is kind to allow you to perform certain tasks using PowerShell. Let’s get things underway!

You will need the following installed before you can even start querying from Office 365 or rather Office 365.

Pre-Requisites
  • .NET Framework 3.5.1 (If you do not have it, you can either activate it via your Windows Features or download it and install here)
  • Microsoft Online Services Sign-In Assistant (Download here)
  • Office 365 Cmdlets (Download here)

 

Installation Process
  • Start Windows PowerShell Session
  • Import the MSOnline module by entering

Import-Module MSOnline

  • Input your credential and store in the variable $MyCred – Notice that the popup will appear as shown below. Just key in your user credential that you used to enter Office 365 Administration Portal

01_Get_Credential 

 

  • Create a new PowerShell Session by keying the following as shown. Just take note of the generic URL used here. From time-to-time, Microsoft may change the URL, however that will depends on Microsoft. (Variables are underlined)

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

02_Get_Session

 

  • Establish the Session – Notice that I am hit with an error, however that is a generic error alerting me that my PowerShell Session Execution Policy is set to restricted.

03_Import_Session_Error

 

  • I simple just set the Execution Policy to “RemoteSigned” via the command.

Set-ExecutionPolicy RemoteSigned

04_Set_Execution_RemoteSigned

 

  • Re-run the “Import-PSSession” line of code.

05_Import_Session

 

  • Establish the connection/session with Office 365 / MS Online by using the following command. If there is no error flag out, then it means that you have successfully connected to MS Online.

Connect-MsolService –Credential $MyCred

06_Connect_MsolService

 

  • First step towards testing, I list the Mailboxes that I have… *OK, this is my test account, therefore only one pathetic account there.*

07_Test_MsolService_GetMailbox

 

  • Listing all the Cmdlets that is available to Office 365 / MSOnline for the Microsoft Exchange component.

08_Get_Commands

 

From the above, we can see that there are pretty a lot of commands that we can execute against Office 365 and therefore it somehow still justify for someone to Administrate your Office 365 subscription. It does not means that once you move to Microsoft Cloud, your support team can be axed and solely depends on Microsoft Technical Support.

Please delete that thoughts until you try out the Technical Support from Office 365 before making such decision!

Just my 2 cents.

 

Regards,
Milton Goh

By | 2013-11-01T11:44:59+00:00 November 1st, 2013|Office 365, PowerShell|0 Comments

About the Author:

Leave a Reply