I created this PowerShell module to help O365 Administrators sign into the their online tenant services using simple verb-noun single command lets (cmdlets). While the general O365 PowerShell (PS) sign-in process is straight forward by itself, there are several lines of PS code that need to be combined and executed each and every logon attempt. This module is designed to help streamline the process of signing into O365 and specific modules that administrators often use. Visit the MS Script Center to get the O365_Logon Module download.
The current O365 components in this module to sign into are:
- Compliance Center Online (CCO)
- Exchange Online (EXO)
- SharePoint Online (SPO)
- Skype for Business Online (SfbO)
- All four components (O365)
All five noun options have both a ‘Connect’ and ‘Disconnect’ verb available.
Connect-CCO – connect to the online Compliance Center
Connect-EXO – connect to Exchange online
Connect-SPO – connect to SharePoint Online
Connect-SfbO – connect to Skype for Business Online
Connect-O365 – connect to all four services with one cmdlet
Disconnect-CCO – disconnects from the online Compliance Center
Disconnect-EXO – disconnects from Exchange online
Disconnect-SPO – disconnects from SharePoint online
Disconnect-SfbO – disconnects from Skype for Business Online
Disconnect-O365 – disconnects from all four services
During the disconnects, the PSSessions are disconnected from the online tenant and the user variable credentials are nullified. Some modules, like the MSOnline module, cannot be currently disconnected without closing the existing PS session. Each of underlining O365 services PS connection scripts are listed on this technet page.
Also included in this module is a Request-Credential cmdlet. This allows you to request a new credential pop-up in case you incorrectly put in the wrong credentials. The module can’t detect good/bad credentials, but there is full logic in place to confirm if you successfully get logged onto a specific O365 service or not. There are cmdlets that call out and present a result from the tenant to display confirmation of actual connections to O365.
You must have the following pre-requisites already installed.
- .Net 4.5.2 (This is a required update for your OS)
- One of the following Windows Management Frameworks, which is the PowerShell version on your client computer. This module only requires PS version 3.0 or higher and no update is needed if you already have PS 3.0 or higher installed:
- Windows Azure Active Directory Module for Windows PowerShell
- Microsoft Online Service Sign-in Assistant for IT Professionals RTW (For Exchange Online connections)
- SharePoint Online Management Shell For SharePoint online connections)
- Windows PowerShell Module for Lync Online (Skype for Business Online) (For Skype for Business online connections)
This module does NOT check for these installs. If you do attempt to use a cmdlet without the proper module(s) installed, PowerShell will error out and tell you what is missing. I have created another PowerShell script, O365_Installs_Connections.ps1, that will help with the installations of all of the requirements for this module to fully function, including a blog post of how to use the script.
SharePoint example with missing module:
I’ve also had issues where my O365 tenant was not fully functional and resulted in similar ‘red’ errors all over PS when logging in. So if this module was working and is now having an issue, log into your O365 admin portal and confirm that services are reporting ‘no issues’.
How to install this module
I know not everyone installs PowerShell modules often, or ever. A module install is extremely easy. Attached to this blog post is the O365_Logon.zip file, or download the zip file from the MS Script Center. You can also use the O365_Installs_Connections.ps1 script to perform the install, however, all you need is to copy/paste the O365_Logon folder into one of the following locations:
How to use this module
Once this module is installed, you can set the execution policy to either Remote Signed or Unrestricted.
Launch Windows PowerShell (‘Run as Administrator’ not required) and type in Connect-EXO. Tab complete also works, so you can tab through any ‘connect’ verb cmdlets on your system. Usually there are not too many ‘connect’ verb options already installed on your client machine.
When you hit the enter key, up comes the credential prompt that also has the message that you need to use your O365 SMTP address account information:
Once you are logged in, a message also appears confirming that you have access to your online tenant. There is logic built into each cmdlet to call out to O365 and present the results.
If the results are not returned correctly, an error message is displayed that you are not connected to the remote session.
Also included are disconnect verbs in this module. This helps in ensuring that your sessions are disconnected. You can also just simply close the current PS Window to close all of your connected sessions.
As I was testing, I sometimes typed in the wrong user name and/or password information. The sessions then errored out and I would have to close the entire PS window to start over. So I made the logon process easier by adding this Request-Credential cmdlet.
You simply use this cmdlet, up pops the credential screen, put in a proper user name and password, then hit ‘OK’. You can then choose which O365 service(s) to connect to. The credentials are saved as a variable and then can be passed into any/all of the connection options.
With bad credentials, if you just try another connect, the current credentials are not reset. I left it this way so that if you’re connected to EXO and then need to connect to SPO for example, the credentials are still available in the current PS session. If you need to flush your credentials, simply disconnect or close the PS window. This is the same process if you’d run the logon code manually.
I hope you find this O365 Logon Module helpful. It should assist you in making your logon to O365 experience within PowerShell quicker and much easier. Thank you.
I’ve been getting some great feedback from engineers. One issue that some have run into, is that when you download files from the Internet, they can marked as potentially unsafe. One work around is to change the file properties. This helps in allowing you to run the module with execution policy of ‘RemoteSigned’. There still could be other reasons within your environment that restrict script usage, but here is a post to help you change the file property of a downloaded Internet resource: http://www.howtogeek.com/70012/what-causes-the-file-downloaded-from-the-internet-warning-and-how-can-i-easily-remove-it/
Updated with version 1.1 on the this page and the script center. Minor changes: added additional help content and cmdletbindering to functions.