Share via


Connect Windows PowerShell to the Service

Applies to: Office 365 for professionals and small businesses, Office 365 for enterprises, Live@edu

After you have installed and configured Windows PowerShell and Windows Remote Management (WinRM) on your computer, you have to connect the Windows PowerShell on your local computer to the cloud-based service to perform tasks in your cloud-based organization.

When you open Windows PowerShell on your computer, you're in the Windows PowerShell session of your local computer. A session is an instance of Windows PowerShell that contains all the commands that are available to you.

The Windows PowerShell session of your local computer, called the client-side session, only has the basic Windows PowerShell commands available to it. By connecting to the cloud-based service, you connect to the Microsoft datacenter's server environment, called the server-side session, which contains the commands used in the cloud-based service.

Before you begin

Before you connect, make sure you have the correct version of Windows PowerShell and WinRM installed and configured on your computer. For more information, see Install and Configure Windows PowerShell.

Verify the account you will use to connect is authorized to connect using Windows PowerShell. For more information, see Control Users' Access to Windows Remote Management.

Connect Windows PowerShell on your local computer to the cloud-based service

  1. Click Start > All Programs > Accessories > Windows PowerShell > Windows PowerShell.

  2. Run the following command:

    $LiveCred = Get-Credential
    
  3. In the Windows PowerShell Credential Request window that opens, type the credentials of an account in your cloud-based organization. When you are finished, click OK.

  4. Run the following command:

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

    Note   The AllowRedirection parameter enables cloud-based organizations in datacenters all over the world to connect Windows PowerShell to the cloud-based service by using the same URL.

  5. Run the following command:

    Import-PSSession $Session
    

    A progress indicator appears that shows the importing of commands used in the cloud-based service into the client-side session of your local computer. When this process is complete, you can run these commands.

Disconnect Windows PowerShell from the cloud-based service

When you're finished using the server-side session, always disconnect Windows PowerShell by running the following command:

Remove-PSSession <session variable>

For example, to disconnect from the server-side session that is defined by the $Session variable, run the following command:

Remove-PSSession $Session

Important   If you close the Windows PowerShell window without disconnecting from the server-side session, your connection will remain open for 15 minutes. Your account can only have three connections to the server-side session at one time.

Need help for specific tasks?

After you've connected to the server-side session, you're ready to perform tasks in the cloud-based service. For detailed instructions, see Use Windows PowerShell in Exchange Online.

For troubleshooting information, see: