Step 3: Connect to Office 365
We’ll start by connecting to Office 365 itself. Again, we don’t have to start here; we can connect to the various components in any order. But we have to start somewhere, so ….
The first thing we need to do here is import the Office 365 module. To do that, run this command from the Windows PowerShell prompt:
Import-Module MsOnline
Admittedly, nothing will seem to have happened. If that worries, and if you want to verify that the module was imported, run this command:
Get-Module
Somewhere in the list of modules that are returned by this command you should see this:
Manifest 1.0 MSOnline {Add-MsolForeignGroupToRole, Add-MsolG...}
If you see MSOnline listed, that means that everything went according to plan.
With the credentials object created (see Step 2: Create a Windows PowerShell Credentials Object) and with the MsOnline module loaded we can now connect to Office 365 by using the Connect-MsolService cmdlet and the following command:
Connect-MsolService -Credential $credential
Notice that all you have to provide is the credentials object ($credential). Based on those credentials, Office 365 will automatically connect you to the correct domain. You do not have to specify your domain name when running Connect-MsolService.
As usual, nothing will seem to have happen after the Connect-MsolService cmdlet finishes running. To verify that you really are connected to Office 365, run this command:
Get-MsolDomain
In return, you should get back something similar to this:
Name Status Authentication
---- ------ --------------
litwareinc.onmicrosoft.com Verified Managed
That’s one Office 365 component down, and three to go.
Step 4: Connect to SharePoint Online
See Also
Connect to Office 365 by using a single Windows PowerShell window