Using Remote PowerShell to manage Office 365 | Part 2/3 5/5 (1) 4 min read

In this article we will learn how to use remote PowerShell for connecting to Office 365 (Windows Azure Active Directory).

If you prefer to get more “straight forward” version of – Connect to Office 365 by using Remote PowerShell, you go to: Connecting to Office 365 with Remote PowerShell– PowerShell Nuggets)

Step 1: Download and install required components

Before we can start the remote PowerShell session to Office 365, we need to download the required cmdlets. Additional pre-requirement is to: install the: Office 365 sign in assistant.

You can find the required software component using the following links:

1. Microsoft Online Services Sign-In Assistant
You can download the Microsoft Online Services Sign-In Assistant by using the following link:
Microsoft Online Services Sign-In Assistant for IT Professionals RTW

Choose the download option

Download the Microsoft Online Services Sign-In Assistant -01.jpg

Choose the right version for your OS (most of the modern OS are 64-bit version).

Download the Microsoft Online Services Sign-In Assistant -02.jpg

2. Office 365Powershell

You can download the indows Azure Active Directory Module for Windows PowerShell by using the following link:
Windows Azure Active Directory Module for Windows PowerShell

Click on the link named:  Azure Active Directory Module for Windows PowerShell (64-bit version)

Install the Azure AD Module.jpg
After the installation of PowerShell cmdlets, we will find a new icon on the desktop named: Microsoft Online Services Module for Windows PowerShell.
(An additional option is to use: start menu > All Programs > Microsoft online services> Microsoft online service module for Windows PowerShell

Microsoft Online Services Module for Windows PowerShell

The Microsoft Online Services Module for Windows PowerShell shortcut includes a command the will imports Office 365 cmdlets to the PowerShell console.

Technically we don’t have to use this shortcut. We can manually import the 365 cmdlets to the PowerShell console by using the command: Import-Module MSOnline

Import  Office  365  cmdlets to  the PowerShell console-03

Step 2: First time configurations

I must admit that the First-time configurations is a little a bit “Naggers” but, after creating the required settings, the next time will be easier. The PowerShell remote connection requires the following configuration settings:

1 – Run as Administrator

To be able to change the PowerShell Execution Policy, we need to run PowerShell console, by using the option: Run as administrator.

Run as administrator-01

Right click on the Microsoft Online Services Module for Windows PowerShell icon and chose the option: Run as administrator.
Run as administrator-02

2 – Setting the PowerShell Execution Policy

PowerShell security policy (“Execution policy”) can be defined by using one of the following options (modes): Restricted, AllSigned, RemoteSigned, and Unrestricted.
(The default mode is: Restricted).
To change the Execution policy open the Microsoft Online Services Module for Windows PowerShell and type the command:

Set-ExecutionPolicy Unrestricted

Set-ExecutionPolicy RemoteSigned-04

To execute PowerShell command, we use the “ENTER” key.

Step 3: Connect to Office 365 by using Remote PowerShell

Open the Microsoft Online Services Module for Windows PowerShell and Type (or copy and paste) the following command:

Connect-MsolService

A pop out windows will appear. Type your credentials by using the UPN (user Principal name) format. For example: admin@o365info.com

Connect-MsolService-05

Note – the user name should have global administrator rights in the Office 365 environment.

Congratulations! You are now connected to the Office 365.

PowerShell Interface is a little bit “stingy” in providing Indication such as: “you are now connected”. In the PowerShell environment, the fact that we did not get any error message indicates that “everything is O.K” (most of the times).

Step 4: Verifying the remote connection

Q: How can we know if the remote session was successfully created?

A: To verify that we are connected, we can use the most basic Office 365 cmdlets:

Get-Msoluser

Verifying the remote connection-06

This command will display a list all Office 365 users. In the screenshot you can see a list of Office 365 users

Summery

In this article we review the following items:

Next step

In part 3 we will learn how to crate Remote PowerShell for managing Exchange:

Part 3: Connect to Exchange Online by using Remote PowerShell

Watch the Video: Connect to Office 365 by – using Remote PowerShell

Using Remote PowerShell to manage Office 365 | Article series index

Now it’s Your Turn!
We really want to know what you think about the article

Print Friendly

Related Post

Please rate this

Eyal Doron on EmailEyal Doron on FacebookEyal Doron on GoogleEyal Doron on LinkedinEyal Doron on PinterestEyal Doron on RssEyal Doron on TwitterEyal Doron on WordpressEyal Doron on Youtube
Eyal Doron
Share your knowledge.
It’s a way to achieve immortality.
Dalai Lama

Leave a Reply

Your email address will not be published. Required fields are marked *