...let John help you code

remote PSsession :throws error

Asked by:
Nov 23, 2016, 22:49


why this command throws an error while connecting to exchange online

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

1 Answer

Answer :



You can try these steps to access Office 365 Using Remote Exchange Management Power Shell:
Step 1
  • Run Windows PowerShell as administrator and run the following command.

  • Set-ExecutionPolicy Unrestricted  

    Step 2
  • On a Windows PowerShell endpoint, run the following command and enter the Office-365 administrator account credentials for authentication in the popup window.

  • $LiveCred = Get-Credential  

    Step 3
  • To establish a remote Windows PowerShell session with Office 365, use the New-PSSession Windows PowerShell cmdlet to connect with the generic remote Windows PowerShell endpoint at http://ps.outlook.com/powershell. Run the following command to create Remote Exchange Shell Session.

  • $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection  

    Note : The user account you use to connect to office 365 Exchange Online must be enabled for remote shell.

    You will be connected by now. If the Microsoft Online Services Sign-in Assistant has been installed, execute the following command:
    Connect-MsolService –Credential $LiveCred