locked
Trouble Calling MsolService and EXOPSSession RRS feed

  • Question

  • Im working on a powershell script that needs to connect to exchange online and AzureAD.  Im using the following to connect to the services:

    ###############  CREATE A REMOTE POWERSHELL OFFICE 365 SESSION  
        "msg * You will be prompted for credentials twice. Please use your office 365 admin credentials"| cmd
        Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
        Connect-EXOPSSession -ConnectionUri https://outlook.office365.us/PowerShell-LiveID
        Connect-MsolService -AzureEnvironment AzureUSGovernment
        #Connect-AzureAD -AzureEnvironmentName 
    
        ###############  CREATE A REMOTE POWERSHELL OFFICE 365 SESSION  ###################

    Exchange connects but I get the following when calling Connect-MsolService:

    +     Connect-MsolService -AzureEnvironment USGovernment
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (Microsoft.Onlin...nectMsolService:ConnectMsolService) [Connect-MsolService], MissingFieldException
        + FullyQualifiedErrorId : System.MissingFieldException: Field not found: 'Microsoft.Azure.ActiveDirectory.Client.Framework.MicrosoftOnlineInstance.AzureUSGov 
       ernmentCloud3'.
       at Microsoft.Online.Administration.Automation.ConnectMsolService.MsolCmdletProcessRecord()
           at Microsoft.Online.Administration.Automation.MsolCmdlet.ProcessRecord() in X:\bt\1067178\repo\src\dev\PowerShell.V1\modules\psmodule\Cmdlets\MsolCmdlet.c 
       s:line 111,Microsoft.Online.Administration.Automation.ConnectMsolService
     
    Connect-MsolService : Field not found: 'Microsoft.Azure.ActiveDirectory.Client.Framework.MicrosoftOnlineInstance.AzureUSGovernmentCloud3'.

    Am I missing something here? Thanks

    Thursday, January 9, 2020 8:19 PM

All replies

  • Connect Msol first and it should work. Old problem which means you have old modules.


    \_(ツ)_/

    Thursday, January 9, 2020 9:25 PM
  • What do you mean old modules? If you are referring to Connect-AzureAD I  cant use it because it does not have all the commands. 
    Thursday, January 9, 2020 9:29 PM
  • Msol and Exchange modules.

    \_(ツ)_/

    Thursday, January 9, 2020 9:38 PM
  • Msol and Exchange modules.

    \_(ツ)_/

    the newer modules dont support all the commands.
    Friday, January 10, 2020 11:47 AM
  • The you have to call the Msol connect first.

    The new MSOnline module does support all commands although, if you have one that is 3 or 4 years old the command names may have changed.

    You need to move with the changes.  The old modules are no longer supported and do not work correctly with the newer version of the cloud.


    \_(ツ)_/

    Friday, January 10, 2020 12:01 PM
  • The you have to call the Msol connect first.

    The new MSOnline module does support all commands although, if you have one that is 3 or 4 years old the command names may have changed.

    You need to move with the changes.  The old modules are no longer supported and do not work correctly with the newer version of the cloud.


    \_(ツ)_/

    the preferred way to connect to exchange online with MFA is to use Connect-ExoPSSession in addition, Connect-MsolService is still widely supported.
    Friday, January 10, 2020 12:40 PM
  • The Msol module has been upgraded frequently and they wil not cooperate with the Exchange connection when used together. Connecting Msol first usually avoids this conflict.

    Upgrade the MsOnlie module and try again.


    \_(ツ)_/

    Friday, January 10, 2020 2:33 PM
  • Hi, 

    If any reply  is useful for you, please mark it as answer.

    Bests, 


    Please remember to mark the replies as answers if they help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, January 14, 2020 7:00 AM