Office 365 Connection Script with Modern Auth - Supports MFA (Multi-Factor Auth)

Script with GUI based connection to all Office 365 services that support Modern Auth and MFA - Exchange Online - SharePoint Online - Skype for Business Online - Azure AD v1 - Azure AD v2 - Azure Resource Manager - Azure Rights Manager - Security and Compliance Center

4.8 Star
20,145 times
Add to favorites
Office 365
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Instructions?
    2 Posts | Last post July 10, 2018
    • What server should I be running this on?  Where can I find instructions on syntax and how to run this script?  Also, is there a description somewhere that tells me what attributes this is changing and why?
    • Scroll down to the 'Resources' section of the download page and there are numerous links there about how to configure your PC or admin server as well as how to use the script.
  • SSO update
    2 Posts | Last post July 09, 2018
    • Very nice script to get into all of the MS parts.  You would think MS would have a single point of entry for all of this, but maybe some day.  Any chance you are planning a update that will allow a single entry of username/password to start all modules?
    • Hi John, to my knowledge, there is no way to enter the password once and use for logging in to multiple services with an account protected by MFA.
      My non-MFA script does handle that though and is available here -
  • Multi sessions
    1 Posts | Last post June 05, 2018
    • Have not tried this script yet, Looks Great. Thanks for Creating it. Question: crossover Cmdlet names from Exchange to Security and Compliance. Does your script add multiple sessions in one Powershell window or are they separate? If they are together, is there any need for custom cmdlet prefixes to differentiate between exchange and Compliance Center?
  • Connections close mid-use
    3 Posts | Last post April 10, 2018
    • As others have said, thank you so much for creating this. When we swapped to MFA I lost use of some great scripts of mine and this resolved that. For some reason, mid-use I will be disconnected. Recently I've been doing mostly single line commands that are not using a script and it will still happen between two commands, not after a five minute break timeout or something similar if that exists. When connecting without MFA I don't have this problem, but with the MFA it happens. I searched your script and couldn't find any setting related to a duration. Any idea what could be causing this?
    • Quick addition: When using the Powershell window that opens via the Exchange Online link I do not have this problem.
    • This is a known issue with PowerShell ISE.
      Does this happen when you run the scripts in EMS ?
  • Powershell window closes when 'OK' is clicked in GUI
    2 Posts | Last post March 25, 2018
    • Hello - Thank you for providing this script.  It sure helps when connecting to Skype for Business in Office 365.  I am running into an issue that I was hoping you could help with.  If I run the script from an already open PowerShell window, it works fine.  I am able to click 'OK' and the GUI window closes allowing me to interact with the PowerShell window.  If I however run the script by right clicking and choosing 'Open with PowerShell', everything works fine until I click 'OK' in the GUI window.  The PowerShell window then closes.  Any ideas would be greatly appreciated.
    • No idea on the underlying issue, but it could be something to do with how the GUI works. I have only ever tested and used by starting PowerShell first, and then running the script from there.
  • Can't get this working on server 2016.
    2 Posts | Last post March 25, 2018
    • I set up brand new patched server 2016.  I cannot get this working.  install microsoft sign in assistance then install-module MSONLINE.  Then import-module MSONLINE.
      Then connect-msolservice.
      I see a quick flash of a logon screen and then error message.  I've been stuck for hours please help what is required to run this thing on windows server 2016????
      PS C:\Windows\system32> Install-Module -Name MSOnline
      PS C:\Windows\system32> import-module MSOnline
      PS C:\Windows\system32> connect-msolservice
      connect-msolservice : Authentication Error: Unexpected authentication failure.
      At line:1 char:1
      + connect-msolservice
      + ~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : OperationStopped: (:) [Connect-MsolService], Exception
          + FullyQualifiedErrorId : System.Exception,Microsoft.Online.Administration.Automation.ConnectMsolService
    • This looks like a user name and password issue.
      Try logging into the Office 365 Portal with those credentials to confirm.
  • Shell Hangs periodically
    3 Posts | Last post December 20, 2017
    • Great script! I just updated to 2-5. 
      I find that the shell window will lock up requiring me to right-click close it.  I can reconnect and be fine again for a random period of time. 
      I will try to replicate this situation on another machine. 
      The workstation is Windows 10. Using it with PowerShell ISE.
    • Yes... it hangs in ISE.
      Seems to be stable in PowerShell.
      I have it hang on multiple workstations with multiple configurations.
      I have had issues with the Exchange PowerShell connection, but none with Azure AD.
      I have updated my doco to reflect using PowerShell rather than ISE.
      I much prefer ISE, but it looks like I need to create my scripts in ISE, and then run in PowerShell.  :(
    • Hi Terry, 
      first of all, great, great script. This is a time saver for many of us.
      As many of us also do want to use ISE, could a part of the solution can be found in this link:
      and this info
      The application will not respond and the UI thread will hang in an Invoke call while handling the OnUserPreferenceChanged notification
      This occurs if a control is created on a thread which doesn't pump messages and the UI thread receives a WM_SETTINGCHANGE message.
      Applications should never leave Control objects on threads without an active message pump. If Controls cannot be created on the main UI thread, they should be created on a dedicated secondary UI thread and Disposed as soon as they are no longer needed.
  • Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
    2 Posts | Last post December 06, 2017
    • Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
      Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
      Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
      Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
      Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
      Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
      Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
      Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
      Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
      Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
      Skype customer Support Number +1 (844) 296 1666 Skype Tech Support Number
    • Please ignore this scam. I have reported to Microsoft.
  • Publish to Powershell Gallery?
    1 Posts | Last post November 30, 2017
    • Great script. You should publish this to powershell gallery so it can easily be installed by "Install-Script connect-o365-mfa -scope currentuser"
      Here's a quick tutorial. Thanks again!  
  • Bad Request
    3 Posts | Last post November 23, 2017
    • I am getting the same issue and we use MFA.  When I run the Exchange Online module by itself it works fine so I know my connection is good.  The Azure AD v2 option works and brings up the new window where I can enter my credentials.  The Exchange Online option only brings up the new window with the error below (doesn't prompt for any sign in):  
      Sorry, but we’re having trouble signing you in. 
      We received a bad request.
      Additional technical information: 
      Correlation ID: 0c0610c3-e607-4163-a478-146b6dcc8553 
      Timestamp: 2017-11-23 16:04:25Z 
      AADSTS90013: Invalid input received from the user. 
    • Sorry I didn't read the first part of the script to manually edit the script to update the $UPN and tenant variables.  Anyway to change this so that it will prompt for the UPN variable?  Will make it much more user friendly for users that are not script editors.
    • Hi Slinghotz,
      I have tried to make the script as easy as possible and to try and minimise the prompts for information as much as possible. That is why I added the UPN variable so that some of the services pre-populate the script with the UPN and save you entering it each time. Currently, only a few Office 365 services pre-populate the UPN from the script. Most force you to enter your UPN as well as your password and MFA code.
      In regards to the prompts you will receive from the MFA script, follow this guide to understand how it works - . 
      Updating my script before you run it helps with SharePoint connections as it updates you connection to point directly to your tenant.
      It really is important to read my guides to ensure your connection experience is pain free.
      If you just want a single script that you edit once with no more prompts to connect to all Office 365 services, download this script - - Note that it doesn't support modern auth / MFA.
11 - 20 of 32 Items