1

In the world of basic authentication, I used to connect to MSOL, Compliance and Exchange in a series that went like this:

        function ConnectToCloud()
        {
            $CloudCredentials = import-clixml C:\tools\CloudCreds.xml
            Write-Host "Connecting To Compliance Online..." -foregroundcolor white -BackgroundColor Green
            $Session1 = New-PSSession -Name "Session1" -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid `
                            -Credential $CloudCredentials -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue
            Import-PSSession $Session1 -Prefix CP -DisableNameChecking -AllowClobber | Out-Null
            Write-Host "Connecting To Exchange Online..." -foregroundcolor white -BackgroundColor Green
            $Session2 = New-PSSession -Name "Session2" -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell `
                            -Credential $CloudCredentials -AllowRedirection -WarningAction SilentlyContinue
            #Import-PSSession $Session2 -Prefix Cloud -DisableNameChecking -AllowClobber | Out-Null
            Connect-MsolService -Credential $CloudCredentials
            Write-Host "Starting the Checks..." -foregroundcolor white -BackgroundColor Green
        }

In the world of Modern Auth, we're supposed to connect to Compliance with:

    Connect-IPPSSession -Credential $CloudCredentials

and connect to Exchange with:

    Connect-ExchangeOnline -Credential $CloudCredentials

the connect to MSOL hasn't changed.

The problem is that when I run Connect-ExchangeOnline, it DISCONNECTS me from Compliance and vice-versa How can I, in a script connect to all THREE services simultaneously, using modern auth?

Thanks!

dragonspeed
  • 145
  • 2
  • 8
  • 1
    Microsoft documentation https://docs.microsoft.com/en-US/powershell/exchange/office-365-scc/connect-to-scc-powershell/mfa-connect-to-scc-powershell?view=exchange-ps is stating (Optional): If you want to connect to an Exchange Online PowerShell module session in the same window, you need to run $EXOSession=New-ExoPSSession -UserPrincipalName [-ConnectionUri -AzureADAuthorizationEndPointUri ] and then import the Exchange Online session into the current one using an specific prefix Import-PSSession $EXOSession -Prefix EXO – Brice May 02 '20 at 14:30
  • Vote for this, you could test. – Jayce May 04 '20 at 09:08

2 Answers2

1

It seems I was using the "preview" module of the Online connection.

If I use the one that you get via the Exchange Online reference, then the following commands work to connect to BOTH compliance and Exchange Online

        $MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1)
        Import-Module "$MFAExchangeModule"
        $CloudCredentials = import-clixml C:\tools\CloudCreds.xml
        Write-Host "Connecting To Compliance Online..." -foregroundcolor white -BackgroundColor Green
        Connect-IPPSSession -Credential $CloudCredentials -WarningAction SilentlyContinue
        Write-Host "Connecting To Exchange Online..." -foregroundcolor white -BackgroundColor Green
        Connect-ExchangeOnline -Credential $CloudCredentials -ShowBanner:$false
        Connect-MsolService -Credential $CloudCredentials
        Write-Host "Starting the Checks..." -foregroundcolor white -BackgroundColor Green

Note - I can't use New-EXOPSSession because it won't let me give it a Credential parameter... Interactive logins don't work so well in a script :(

dragonspeed
  • 145
  • 2
  • 8
0

I am glad to know the issue has been resolved, please mark the helpful replies as answers, this will make answer searching in the forum easier and be beneficial to other community members as well.

Jayce
  • 769
  • 4
  • 5