Connecting PowerShell to Office 365

  1. On your local computer, open Windows PowerShell and run the following command.
    $UserCredential = Get-Credential

    In the Windows PowerShell Credential Request dialog box, type your Exchange Online user name and password, and then click OK.

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

    Note   If you are an Office 365 operated by 21Vianet customer in China, use the following value for the ConnectionUri parameter: https://partner.outlook.cn/PowerShell.

  3. Set-ExecutionPolicy RemoteSigned > Select Yes
  4. Run the following command.
    Import-PSSession $Session