Configuring Windows PowerShell To Support Office 365

Good evening to all the Office 365 nerds out there. This article will be on how to configure Windows PowerShell in your client operating system to support Office 365 (i.e. SharePoint Online Management shell, Exchange Online Management Shell, Skype for Business Online Management Shell and Office 365 Security & Compliance center). Well, it’s a known fact that Microsoft has released the PowerShell module for all these products (SharePoint Online, Exchange Online, Skype for Business Online and Office 365 Security & Compliance center) separately and you can use that to manage these products separately. Listed below are the links to download those modules:

Hence, if you’re the guy who plays the IT administrator role in your company and if you’re the one who has Office 365 global admin role assigned to you and takes care of managing Office 365, the chances are that your desktop can look very messy, as shown in the image below, while you’re using the management shell. You’re definitely going to have a hard time in managing them.

management shel

Thus, the idea is to show how to configure PowerShell to support all these modules and be successful in managing Office 365 from a single PowerShell Window.

Let’s get into the detailed steps, now:

Note: Please bear in mind, that you need to have Office 365 global admin access to perform these steps.

  1. Please install Microsoft .NET Framework 4.5.x and then either the Windows Management Framework 3.0 or the Windows Management Framework 4.0. in your PC.

  2. As far as Skype for business online module to function is concerned, you need a 64-bit operating system and hence please make sure you’re running a 64 bit version of Windows otherwise you will end up getting an error message, as shown in the image  given below: 

    error

  3. Listed below are the 64-bit version of Windows, that you can use,

    • Windows 8.1 or Windows 8
    • Windows Server 2012 R2 or Windows Server 2012
    • Windows 7 Service Pack 1 (SP1)*
    • Windows Server 2008 R2 SP1*

  4. Once that’s done, you need to install the modules that are required for Office 365, SharePoint Online and Skype for Business Online. Listed below are the links to download those modules.


  5. Once you’re done installing all the modules, you need to configure Windows PowerShell to run the signed scripts for Skype for Business Online, Exchange Online and the Security & Compliance Center. To do this, run the following command in an elevated Windows PowerShell session:

    Set-ExecutionPolicy RemoteSigned

    Set-ExecutionPolicy RemoteSigned

  6. Now, in order to identify whether you’re running Windows PowerShell, using elevated permissions or normal mode, please check the prompt on your PowerShell screen.

    • PS C:\Windows\System32>,  Elevated permissions
    • PS C:\Users\UserName> Normal mode
      ,
  7. Now, run the next command, mentioned below, to pass your Office 365 user name and password to Windows PowerShell in an encrypted way. Once that’s done, you will get a Windows dialog box prompting for your credentials, as shown in the image below: 

    $credential = Get-Credential

    $credential = Get-Credential

  8. Now, key-in your Office 365 credentials and click OK, as shown below:

    credentials

  9. In order to identify whether your credential object has been created successfully or not, please run the command, mentioned below, as shown in the image below and it should return the value.
      
    Note: Windows PowerShell will never tell you anything, when things go fine and will silently pass on to the next line .It only yells at you, when something goes wrong. That’s the funny thing about Windows PowerShell.

    $credential

    $credential

  10. Now, we can start connecting to Office 365. For it, please run the command, given below: 

    Import-Module MsOnline

    Import-Module MsOnline

  11. Once that’s done, in order to verify whether the module was imported successfully or not, you need to run the command, mentioned below. This should return the value, as shown in the image below: 

    Get-Module

  12. Somewhere in the list of the modules that are returned by this command, you should see something that looks like this:

    Manifest 1.0 MS Online {Add-MsolForeignGroupToRole, Add-MsolG...}.

    If you see MSOnline listed, that means that everything went according to the plan.

  13. Since we have verified that the credential object has been created and also the MSOnline module has been loaded successfully, the next step would be to connect to Office 365, using the Connect-MsolService cmdlet. For it, run the command, given below: 

    Connect-MsolService -Credential $credential

    Connect-MsolService -Credential $credential

  14. In order to verify whether you have successfully logged into your Office tenant or not, please run the command given below and verify your domain information, as shown in the image below. In my case, my domain name for Office 365 is “vigx” and you can see it in the image below:

    Get-MsolDomain

    Get-MsolDomain

  15. After performing all the above mentioned we have successfully verified that we are able to establish a connection to the Office 365 tenant using our user name and password which has Global admin access in Office 365. Now the next steps would be to create a connection to each modules separately (i.e. SharePoint Online, Exchange Online , Skype for Business Online & Security and Compliance center for Office 365 ).

  16. Initially, let’s get started with SharePoint Online by running the following command:

    Import-Module Microsoft.Online.SharePoint.PowerShell –DisableNameChecking

    Here, the “DisableNameChecking” switch suppresses the below mentioned warning.

    Warning: The names of the some commands, that are meant for the import from the module 'Microsoft.Online.SharePoint.PowerShell' includes unapproved verbs that might make them less discoverable. To find the commands with the unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.

  17. In order to connect to SharePoint Online, you need to supply two pieces of information: your credentials and the URL of your SharePoint Online admin site. 

    Note: You can get your SharePoint Online tenant URL by opening the tenant admin page. Check the screenshot below: 

    URL

    This is how the format will look like:

    Admin URL: https://vigx-admin.sharepoint.com

    Connect-SPOService -Url: https://vigx-admin.sharepoint.com -credential $credential

  18. Once that’s done, please go ahead and run “Get-SPOSite” command, as shown below.This should list all the SharePoint Online sites.

    results

  19. If you successfully get the list of all SharePoint Online sites, your command ran successfully.

  20. Also try running Get-MsolUser and see the result. This will return the list of all the users in Office 365 .This means, you can now manage both SharePoint Online and Office 365 from the same Windows PowerShell Window.

    window

  21. Now, let’s take a look on how to connect to Skype for Business Online (formerly as Lync Online)

    Note: Connecting to Skype for Business Online (and to Exchange Online or the Security & Compliance Center) is different than connecting to Office 365 or to SharePoint Online. That’s because the Skype for Business Online and Exchange Online cmdlets does not get installed on your computer like Office 365 and the SharePoint Online cmdlets do. Instead, each time you sign in, the appropriate cmdlets are temporarily copied to your computer. When you sign off, those cmdlets are then removed from your computer.

  22. In order to connect to Skype for Business Online, please run the command, given below, to import the Skype for Business Online module. For it, run the command, given below: 

    Import-Module SkypeOnlineConnector

    Import-Module SkypeOnlineConnector

    Note: The first time, you might see some warning message, which can be safely ignored.

  23. Once the module has been made to import, run the command, given below, to initiate a new Sfbo session by running:

    $sfboSession = New-CsOnlineSession -Credential $credential

    Note: By running the command, given above, we have successfully created a remote PowerShell session. The command, given above, is used to connect to an instance of Windows PowerShell running on one of the Office 365 Servers.

    $sfboSession = New-CsOnlineSession -Credential $credential

  24. Once that’s done, you need to run the command, mentioned below, to download the “Skye for Business Online scripts /cmdlets” and the other items. As already mentioned before, Skype for Business Online commands are not similar to SPO cmdlets, Sfbo cmdlets are required to be loaded every time you plan to use PowerShell to manage Sfbo. Now, let’s load sfbo cmdlets to PowerShell by running the command, mentioned below (you can notice the progress bar in the image below, loading the cmdlets to Windows PowerShell).

    Import-PSSession $sfboSession

    Import-PSSession $sfboSession
  25. Once Windows PowerShell is done loading the sfbo cmdlets, you should notice something like this as shown in the image below. If you notice this in your screen, you have successfully made a connection to Skype for Business Online.

    connection

  26. You can verify your connection to Skype for Business Online by running the command, given below: 

    Get-CsOnlineUser -Identity [email protected]

    Note: This command will give the information for the user, who has his UPN/SIP ID as [email protected].

    UPN/SIP ID

  27. Till now, we have seen, how to configure Windows PowerShell to support SharePoint Online and Skype for business online. Now , let’s take a look at how to configure Windows PowerShell to support Exchange Online.

  28. In order to proceed further, please run the command, given below, which creates a remote Windows PowerShell session with Exchange Online.

    $exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection

    Note: Why is the command for connecting to Exchange Online more complicated than the command to connect to Skype for Business Online? Technically, it’s not: both the commands do the exact same thing. However, the Skype for Business Online team created its own cmdlet—New-CsOnlineSession—that hides some of the parameters (like Authentication and AllowRedirection) that are used when connecting to Exchange Online. Instead of requiring you to type that information yourself, the Authentication and AllowRedirection parameters are effectively built in to the New-CsOnlineSession cmdlet. You have to type those parameters when connecting to Exchange Online because Exchange Online uses the standard New-PSSession cmdlet to connect to Office 365. The disadvantage is that, you have a little more typing to do. The advantage is that, you don’t have to download and install an Exchange Online module. This will start loading the modules, as shown in the screenshot below:

    modules

  29. Once you’re done running the command given above, please run the command given below, to import the Exchange Online remote session, just as we did for Skype for Business Online. Please check the screenshot below:

    Import-PSSession $exchangeSession –DisableNameChecking

     Import-PSSession $exchangeSession –DisableNameChecking

  30. Once you’re done running the command mentioned above, you would get the results, as shown in the image above.

  31. After you get the desired results in the screen, try running the below mentioned command. You should see information about your Office 365 domains, that are configured for the Email addresses in Exchange Online.

    Get-AcceptedDomain

    Get-AcceptedDomain

  32. This confirms that you have successfully connected to Exchange Online. You can also verify that by running the “Get-Mailbox” command as shown in the Email, given below. This should return the Mailbox information of the users, who are in Office 365.

    Get-Mailbox

  33. So far, we have seen how to manage the user administration/license management for Office 365 , SharePoint Online, Exchange Online & Skype for Business Online, using Windows PowerShell. Now, let’s see how to manage the Security and Compliance center in Office 365, using Windows PowerShell .

  34. The connection instructions for the Security & Compliance Center are very similar to those for Exchange Online, but with a slight difference. Let’s take a look at it. To start, please run the command, given below, which creates a remote PowerShell session with the Security & Compliance Center,

    $ccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $credential -Authentication Basic –AllowRedirection

  35. This will start loading the modules, as shown in the image below: 

    modules

  36. In order to import the cmdlets for “Security and Compliance center” run the command, given below. This should look similar to the Exchange Online cmdlet. The DisableNameChecking switch isn't required here as there are no unapproved verbs in the Security & Compliance Center. But the additional -Prefix cc parameter and value is something different here. The Exchange Online and the Security & Compliance Center share some cmdlets, that have exactly the same names and provide the same functionality. Get-RoleGroup is an example.

    Import-PSSession $ccSession -Prefix cc

    Import-PSSession $ccSession -Prefix cc

  37. Now, you can verify the result of the command in the screenshot above.

  38. In order to verify whether you have been successfully connected to “Security and Compliance center” in Office 365, please visit this link and try executing the cmdlets there and see the results.

  39. Thus, we have connected to all the instances of Office 365 (Office 365 user/license management, SharePoint Online, Exchange Online, Skype for Business Online & Security and Compliance center in Office 365), using Windows PowerShell and we also saw  how to execute the appropriate cmdlets to manage them.

  40. Now, run the command, mentioned below, to get the active sessions that are running .For that run the Get-PSSession,

    The Get-PSSession cmdlet should show you that you have at least three remote sessions open, one for Skype for Business Online, one for Exchange Online and one for the Security & Compliance Center (it’s possible you could have more than three remote sessions running, depending on whether you’ve used this instance of Windows PowerShell to connect to something else, besides the Office 365 services). You should see something similar to the following.

    sessions

  41. Since we have verified the active sessions that are running, now run the below command one at a time to close the session. If you just close the Windows PowerShell window, your Skype for Business Online remote connection will remain active for the next 15 minutes or so. Because Skype for Business Online limits the number of simultaneous connections that any one person or any one domain can have open, that could be a problem. With Skype for Business Online, an individual administrator can have, at most, three open connections at one time, and a domain can have a maximum of nine open connections. If you sign in to Skype for Business Online and then exit without properly closing the session, that session remains open for the next 15 minutes or so. As a result, that’s one fewer connection available to you or to other administrators in your domain. Thus, run the command, given below, to close the remote sessions for Skype for Business Online, Exchange Online, and the Security & Compliance Center gracefully.

    Remove-PSSession $sfboSession
    Remove-PSSession $exchangeSession
    Remove-PSSession $ccSession

  42. If you prefer to close all the sessions at the same time without doing it one at a time, please run the command, given below:.

    Get-PSSession | Remove-PSSession

  43. The commands, mentioned above, will stop the PowerShell sessions for Skype for Business Online, Exchange Online, and the Security & Compliance Center gracefully but not SharePoint Online and hence to stop the session for SharePoint Online , run the below mentioned command .

    Disconnect-SPOService

    Disconnect-SPOService

  44. In order to verify whether we have successfully disconnected from SharePoint Online service or not, run the command given below and it should throw you an error.

    error

  45. This confirms that you have successfully disconnected from SharePoint Online management shell.

    Thus, we have seen how to configure Windows PowerShell to support SharePoint Online Management shell, Exchange Online Management Shell, Skype for Business Online Management Shell and Office 365 Compliance center.

Up Next
    Ebook Download
    View all
    Learn
    View all