Connect Windows PowerShell to the Service


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

Topic last modified: 2013-01-24

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 start Windows PowerShell, 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, has only 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. This 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 that the account you will use to make the connection is authorized to connect by 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, point to All Programs, click Accessories, click Windows PowerShell, and then click Windows PowerShell.

  2. Run the following command:

    $LiveCred = Get-Credential
  3. In the Windows PowerShell Credential Request window, type the credentials of an account in your cloud-based organization. Then, click OK.

  4. Run the following command:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $LiveCred -Authentication Basic -AllowRedirection
    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

    Commands that are used in the cloud-based service will now be imported into the client-side session of your local computer, as tracked by a progress bar. 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 have only 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 the following video: Office 365: Troubleshooting PowerShell for Exchange Online.

For more troubleshooting information, see Windows PowerShell: FAQs for Administrators.

Related help topics
No resources were found.