I am trying to connect to PowerShell using the Connect-ExchangeOnline command but I receive the following error. Any ideas?
New-ExoPSSession : .
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\1.0.1\ExchangeOnlineManagement.psm1:445 char:30
+ ... PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-ExoPSSession], Exception + FullyQualifiedErrorId : System.Exception,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession 7 5 Answers
Please try to use the cmdlet as follows:
Connect-IPPSSession -PSSessionOption
$EXOSession = New-ExoPSSession -pssessionoption
Import-PSSession $EXOSession -Prefix EXO 2 The newest version of Exchange Online module requires PowerShell V7. As soon as I installed V7 it worked fine.
Per:
1EXO V2 module is supported in PowerShell 7.0.3 or later
I was able to resolve a similar issue by switching my default web browser in Windows 10 to the Chromium Edge browser. I brought up the login window once, then switched Firefox back to my default browser and it still worked.
PowerShell v7 is not required to use the ExchangeOnlineManagement module, but is an acceptable workaround. It uses the account logged into the default web browser for authentication, which wasn't an acceptable solution for me. It led me to switching the default browser, though, which resolved my initial problem.
Removing the security baseline from Intune and resyncing by rebooting fixed the issue in my case.
Here's a script that I use to connect. Please fill in your default username and make sure to run the prerequisites in the comments at the top (review first of course)
And if you're using this non-interactive you'll want to look up how to store your credentials securely and how to use those stored credentials, replacing the Get-Credential section with your configuration
# Requires: .Net 4.5, Windows Management Framework 5.1 (see )
#
# Run Once:
# Set-ExecutionPolicy RemoteSigned; Get-ExecutionPolicy
# Install-Module PowerShellGet -Force
# Install-Module –Name ExchangeOnlineManagement
#
#
$exo = New-Module -AsCustomObject -ScriptBlock { $UserName = "Default.Username@domain" $UserCredential = Get-Credential -message "Enter 365 admin credentials" -UserName $UserName function IsConnected(){ try{ if ( @($(get-mailbox -resultsize 1 -WarningAction silentlycontinue)).count ` -eq 1 ) {return $true} } catch {} return $false } function Connect(){ $result = "Unfinished" if ($this.IsConnected()) { $result = "Success" } else { $UserCredential = $this.UserCredential Connect-ExchangeOnline -Credential $UserCredential if ($this.IsConnected()) { $result = "Success" } else { $result = "Fail" } } switch($result){ "Unfinished" {Write-Warning "`nAn unknown error occured in .Connect(), Appears to have ended while unfinished";break} "Success" {Write-host "`nSuccessfully connected to Exchange 365";break} "Fail" {Write-Warning "`nFailed to connect to Exchange 365";break} default {write-warning "`nAn unknown error occured in .Connect(), result code unrecognized";break} } # old style #$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection #Import-PSSession $Session -DisableNameChecking -AllowClobber } function ConnectMsol(){ Connect-MsolService -Credential $UserCredential } function Disconnect(){ Disconnect-ExchangeOnline # old sytle #Remove-PSSession $Session } function Cycle(){ $this.Disconnect() $this.Connect() } Export-ModuleMember -Function * -Variable *
}
$exo.Connect()
#$exo.ConnectMsol()
<#
# --- Azure AD ---
#
# --- Azure AD ---
#> 9