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.

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



  • 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 – Credential $MyCred –Authentication Basic –AllowRedirection



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



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

Set-ExecutionPolicy RemoteSigned



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



  • 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



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



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



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.


Milton Goh

Using PowerShell against Office 365

Leave a Reply

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

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