Today new issue, new solution 🙂
In this article I will discuss an error “Access is Denied” while creating new session for Exchange Online (“Microsoft.Exchange”) using SharePoint Online Management Shell or Windows PowerShell.
In one of my previous blog I explained how to execute Exchange Online PowerShell cmdlets through SharePoint Online Management Shell or Windows PowerShell – Office 365 – Executing Exchange Online PowerShell cmdlets through SharePoint Online Management Shell or Windows PowerShell. Creating remote PowerShell session.
In our one of the recent project we need to test one Exchange Online PowerShell cmdlet for changing the primary address of the one user. So we followed the steps from the blogs.
Issue / Error: While following the steps mentioned in the article, on step for creating new session for “Microsoft.Exchange” as
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credential -Authentication Basic -AllowRedirection
Here credentials are our Office 365 Global Administrator account credentials.
While executing this step we are getting following exception:
New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message : [ClientAccessServer=PN1PR01CA0108, BackEndServer=maxpr0101mb1738.indprd01 .prod.outlook.com,RequestId=785 13643-a7ea-4a20-b3c9-f4447b24ffb0, TimeStamp=1/17/2018 2:35:55 PM] Access Denied For more information, see the about_Remote_Troubleshooting Help topic. At line:1 char:12 + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ... + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin gTransportException + FullyQualifiedErrorId : -2144108477,PSSessionOpenFailed
Our Findings / Solution: We are wondering since we already executed Exchange Online commands previously through SharePoint Online Management Shell and those seems to be working fine. So what happen suddenly.
We google bit, found couple of blogs mentioning change the Password for the user through which we are connecting to Office 365 or verify user name and password but those seems to ok (https://support.microsoft.com/en-in/help/2905767/-access-is-denied-error-when-you-connect-to-exchange-online-by-using-r ). But we have – Password Never Expire policy set there. We re-verified the permission for the user but user is Global Administrator.
After long time we have realized that we have enabled the “Multi Factor Authentication (MFA)” for our users.
MFA was requiring not only to put the credentials but also the App Code from Microsoft Authenticator App. And there is another approach to connect to Exchange Online when MFA is enabled we need to install the “Exchange Online Remote PowerShell Module” and we need to use the Connect-EXOPSSession cmdlet to connect. I’ll cover all the details regarding “Exchange Online Remote PowerShell Module” in next article.
Thanks for Reading 🙂
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.
Stay tuned on Knowledge-Junction, will come up with more such articles.