Connecting to your Office 365 tenant
You may already be familiar with how Microsoft uses the term tenant. For those who are new to Office 365, understand that a tenant refers to a set of Office 365 services that are isolated to a single customer. In layman's terms, this a is subscription. However, a tenant can have multiple subscriptions associated with it, for the various plans in Office 365 or Windows Azure. In fact, a single customer may choose to have more than one tenant, such as a development tenant and a production tenant.
Assuming you are the global administrator for your tenant, PowerShell will connect you to the correct tenant based on the provided username and password. This is possible because DNS suffixes used in usernames must be unique to a single tenant; they can't be used for more than one tenant at a time.
Let's connect to our tenant. We start this process by launching the Azure Active Directory module for PowerShell.
Type the following command and hit Enter:
# Import-Module AzureAD ## This isn’t needed if you open Azure AD PowerShell from the Start Menu using the installed shortcut.
Connect-MsolService
You will see a dialog box like this one, where you can enter your username and password:
If the dialog box you see looks more like a standard Windows credentials box (like the kind you would see if you ran the Get-Credential command), this means you're using an older version of the PowerShell module that doesn't support advanced multi-factor authentication (Adallom):
It may still work, but in some cases, you won't be able to authenticate successfully this way. In such a case, it's best to go download the current version of the PowerShell module which does support advanced authentication.
If the connection is successful, it will not produce any output. That's normal. A failure would generally be displayed in red text, like any other PowerShell error message:
Now that you're connected, you can use other PowerShell commands for Office 365 such as Get-MsolUser or Get-MsolDomain.