Forum Discussion

Roger Roger's avatar
Roger Roger
Iron Contributor
Aug 23, 2018
Solved

Connect to Exchange Online(MFA enabled)

Hi experts i am using exchange hybrid environment. we have enabled MFA,  From one of my server i am using below commands on windows powershell  to connect to exchange online. i am able to connect successfully.

Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch "_none_"}|select -First 1)

$Session=New-ExoPSSession

Import-PSSession $Session -Verbose -AllowClobber

When i execute the below command from my laptop from windows powershell i am getting the below error

PS C:\Users\user1.MYDOMAIN> Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter Micr
osoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch "_none_"}|select -First 1)
Import-Module : Cannot bind argument to parameter 'Name' because it is null.
At line:1 char:15
+ ... port-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\")  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Import-Module], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ImportModul
   eCommand

  • Well, do you have the ExO MFA module installed on the laptop? If so, what does the following resolve to:

    $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch "_none_"}|select -First 1)
  • Well, do you have the ExO MFA module installed on the laptop? If so, what does the following resolve to:

    $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch "_none_"}|select -First 1)
  • If you’ve installed the exo powershell modular on the machine. You should just type in connect-exo and hit tab. Can’t rememebr off top head it auto complete to connect-exosession or online can’t recall but then it prompts threw mfa etc. not sure if there is a reason for all that manual importing?

Resources