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
(44)
16,848 times
Add to favorites
Office 365
10/2/2017
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Hangs?
    7 Posts | Last post October 31, 2017
    • Terry,
      
      After I complete signing in and the EXOP session is done downloading commandlets, my session hangs at "Completed running the script to Connect to Exchange Online - Run the cmdlet - Get-Mailbox - to test connection"
      
      Any idea why?
    • Yes.
      You need to click OK to finalise the connection and close the connection GUI.
      All mentioned in the support link.
      This allows you to connect to multiple services before closing the GUI. 
    • Hi Terry!
      
      I have a same problem, but when I click ok button, Gui and Ps window was closed.
      Do you have a idea why i have this?
      
      Than you.
    • Dragi,
      Can you please provide a bit more information to what exactly happens.
      Also, confirm you are using version 2.5
      Version 2.5 was updated to keep the GUI open until you click OK. This allows you to connect to multiple services without starting the original script again.
      Also, once you click OK, the GUI closes and PowerShell connection finalises and you can run your associated scripts.
      Plus - Do NOT use PowerShell ISE with this script as the EXO component freezes in ISE.
    • Hi Terry!
      
      Yes i use 2.5 version. I don't use ISE. Everythng work fine, until i click ok. Not only gui window was closed, powersehll window was closed to. I haven't got any ps window where can i writie commands.
    • I have never received an error like that and no-one has mentioned it.
      Make sure you follow my support links and have installed all the pre-requisites.
      Also -
      Does it happen on ALL the Office 365 services, or just a single one?
      Does it happen on multiple computers (make sure you prepare the workstation by installing the pre-requisites) ?
    • Dragi,
      
      Forgive me if this is an obvious question, but the OCD in my has to ask...
      
      Are you by chance launching the script from outside a PS environment (by double clicking for example)?  You need to launch the PS console first, then execute the script inside that window.  Otherwise it will only open the PS console long enough to execute the script.
      
      I made it easier for myself to run the script by putting the script in C:\Windows\System32\WindowsPowerShell\v1.0 so it was part of the default path.
      
      So I just open a PowerShell window and type "Connect-O365-MFA.ps1" to trigger the connection window.
      
      HTH.
      -Bozford
  • Generic version?
    2 Posts | Last post October 21, 2017
    • Is it possible to get a generic version of this script?
      
      I work for an MSP so I'm constantly having to connect to different Office 365 tenants but this requires that you edit the script and define a specific one.
      
      Thanks.
    • By memory, the only time the the $Tenant variable is used is for the SharePoint URL.
      You could simply put a hash symbol - # - at the front of the two variable lines 
      $Tenant
      $UPN
      This would then comment those lines out and not run them as part of the script.
      As this is for Modern Auth, the majority of services will make you prompt for the UPN anyway.
  • Adding Complaince Center - Solution
    4 Posts | Last post October 02, 2017
    • Thanks to Vasil Michev for solving this in the community thread:
      
      https://techcommunity.microsoft.com/t5/Windows-PowerShell/Can-I-Connect-to-O365-Security-amp-Compliance-center-via/m-p/103642
      
      "It uses the same module and the same cmdlet, just differnt parameters. Simply open the CreateExoPSSession.ps1 from the install dir, and you will see it."
      
      That leads to something like the following to get the Compliance Center commandlets:
      
      Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch "_none_"}|select -First 1)
      $MFCCPSSession = New-ExoPSSession -ConnectionUri 'https://ps.compliance.protection.outlook.com/PowerShell-LiveId'
      import-pssession $MFCCPSSession
      
      I look forward to your next script verion that includes this!
      
      Bozford
    • Terry, 
      
      I tried to contribute to this code gallery entry, but it ended up creating a new one.
      https://gallery.technet.microsoft.com/Add-Compliance-Center-91c08cb6
      
      If you want to incorporate what you want, I'll take mine down so there isn't a fork.
      
    • Awesome !!!
      Will look at it over the weekend.
      Cheers,
    • Thanks Bozford.
      I have updated the script to include the Security and Compliance Center. Thanks for the heads-up on that update !!!
      Also, thanks for your tips on stopping the auto-close on the form. I have documented that for future reference. I found the setting to change inside SAPIEN.
      And of course you are given credit inside my script  - :)
      Thanks for the help. 
      It is great when everyone works together in the community.
  • Add security and compliance center?
    3 Posts | Last post September 06, 2017
    • Great script, but I am missing the button to connect to the security and compliance center (https://ps.compliance.protection.outlook.com/powershell-liveid/)
      
      Maybe it's a good idea to add that one too?
    • Unfortunately the Security and Compliance Center doesn't support PowerShell connections with MFA as of 31 July 2017. Currently, if you want to manage the SCC via PowerShell, you can only connect with accounts that are not MFA enabled. You can however manage the SCC via the SCC Portal with an MFA enabled account.
      
      You can voice your support for inclusion here -
      https://office365.uservoice.com/forums/289138-office-365-security-compliance/suggestions/18931219-security-compliance-center-powershell-adal-sup
    • Hi Terry!
      
      Support for the Security and Compliance Center was added August 17 using the Connect-IPPSSession commandlet (WOOHOO!!!), but I can't for the life of me figure out how to import the commandlet like you do with the new-EXOPSSession.
      
      https://technet.microsoft.com/en-us/library/mt811266(v=exchg.160).aspx
      
      This is the last remaining piece I believe!  Now admins should be able to administer O365 like the first class paranoid citizens we should be!
      
      P.S. Great solution.  You are the king.  Thank goodness for people like you.
  • Awsome script
    2 Posts | Last post August 31, 2017
    • Do you have the possibilities to add fonctions like "Connect to On-Premises Exchange" or "connect to On-Premises Skype-4B". And maybe add the possibilities to install all the requierments like Azure AD PowerShell and the others. I was using this with another script publish by Mike O'Neill "O365_Installs_Connections.ps1". Well thanks a lot for sharing this.
      
      Regards, 
      
      Jonathan
    • Thanks for the feedback Jonathan.
      I have a Hybrid / Exchange Online Connection script - 
      
      https://gallery.technet.microsoft.com/Office-365-Hybrid-Azure-354dc04c 
      
      Which connects to Local Exchange and all Office 365 services without MFA. 
      I created a dedicated MFA connection script due to the inability to re-use the credentials multiple time like the non-MFA connection scripts.
      
      I have never really dealt much with SfB so I don't have any connection script for that as yet.
      
      In regards to requirements, it is critical to look at the support section at the top of my scripts as that will have links to my blog for articles on how to build your PC to include all the pre-requisites.
       
      Check out this link - http://www.365admin.com.au/2017/01/tutorials.html
      Look at the top section for Configure your Administration PC or Server.
  • Just a great script!
    2 Posts | Last post August 31, 2017
    • Thanks so much for posting this. We've just enabled MFA for all users and this is a godsend!
    • Thanks for the feedback. 
      Keep your eye out for a Office 365 daily admin pack coming soon. I am currently working on a bunch of daily admin tasks to bundle together.
      You can also follow me on LinkedIn - https://www.linkedin.com/in/terry-munro/
  • Unable to connect to EXO
    2 Posts | Last post August 14, 2017
    • Great script!  I tried it the first time and it failed.  Here is the output:
      
      Import-Module : Cannot bind argument to parameter 'Name' because it is null.
      At C:\Connect Online Services\Connect-O365-MFA-v2-0-Signed.ps1:95 char:17
      + ... port-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA + "\Apps\2.0\" ...
      +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidData: (:) [Import-Module], ParameterBindingValidationException
          + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ImportModul
         eCommand
      
      New-ExoPSSession : The term 'New-ExoPSSession' is not recognized as the name of a cmdlet, function, script file, or
      operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
      again.
      At C:\Connect Online Services\Connect-O365-MFA-v2-0-Signed.ps1:96 char:17
      +         $EXOSession = New-ExoPSSession -UserPrincipalName $UPN
      +                       ~~~~~~~~~~~~~~~~
          + CategoryInfo          : ObjectNotFound: (New-ExoPSSession:String) [], CommandNotFoundException
          + FullyQualifiedErrorId : CommandNotFoundException
      
      Import-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid value for
      the argument, and then try running the command again.
      At C:\Connect Online Services\Connect-O365-MFA-v2-0-Signed.ps1:97 char:20
      +         Import-PSSession $EXOSession -AllowClobber
      +                          ~~~~~~~~~~~
          + CategoryInfo          : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException
          + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand
      
      I ready the script, and searched in the LocalAppData but did not find the Microsoft.Exchange.Management.ExoPowershellModule.dll.
      
      Am I missing somthing?
    • Nevermind!  I found the missing .DLL.  Here's the fix:
      
      https://technet.microsoft.com/en-us/library/mt775114(v=exchg.160).aspx
  • Awesome!
    2 Posts | Last post May 16, 2017
    • I don't have a question, just wanted to comment and say thank you for making this!  It actually helped my troubleshoot a MFA issue I was having and all is well now.  I'll be sure to have my co-workers use this as well.
      
      Thanks!
    • Thanks Chris. Happy to share my script and make your team's work that little bit easier.
      Cheers,
  • Proxy update
    3 Posts | Last post May 07, 2017
    • Hi,
      Great script. I would add the following to cover case where proxy.pac is in use and no direct connection is possible from the Workstation running the script:
      $proxysettings = New-PSSessionOption -ProxyAccessType IEConfig
      ...
      $EXOSession = New-ExoPSSession -PSSessionOption $proxysettings
      ...
      $SFBOSession = New-CsOnlineSession -SessionOption $proxysettings
      ...
      
      This allows to connect when a proxy.pac is configured.
      
      Best Regards,
      Mikael
    • That's a great suggestion. Unfortunately I have no environment with a proxy setup to test it in. I would love to hear if you got it working in a proxy environment with that change.
    • Awesome script Terry. I was looking for it since long time.
21 - 29 of 29 Items