Avatar of qvfps
qvfps
 asked on

Cannot Connect to Exchange Online Using PowerShell

We have several tenants using office 365.  One of these was locked down by an employee who is no longer with the company.   I need to connect to it using PowerShell to make some changes.  

I am using an account which is a global admin and an Exchange admin.  I have tried from my computer and from a computer on the local network and whatever I have tried I get the following error message:


New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message : Access is denied. For more
information, see the about_Remote_Troubleshooting Help topic.
At line:4 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
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 line:5 char:18
+ Import-PSSession $Session -DisableNameChecking
+                  ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand


Here are the Powershell commands I am using.  They work connecting to other tenants

$adminUPN="GlobalAdmin@myco.com"
$orgName="My Company"
$userCredential = Get-Credential -UserName $adminUPN -Message "Type Password"
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

Any suggestions would be appreciated.
PowershellMicrosoft OfficeExchange

Avatar of undefined
Last Comment
qvfps

8/22/2022 - Mon
Jose Gabriel Ortega Castro

Hello there, Welcome to EE and thank you for your question.

Can you say if the user has Multi Factor Authenticator Enabled or not?

Jose

ASKER CERTIFIED SOLUTION
Shabarinath TR

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
M A

Agree with Shabarinath.
Please login to EAC and try downloading from here.
 Capture84.JPG
qvfps

ASKER
Multifactor is not enabled for this tenant.   I have previously downloaded and installed the above module but I will try it again and see if it makes any difference.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
qvfps

ASKER
Thanks for the assistance.   accessing it with Connect-EXOPSSession -UserPrincipalName worked.