Managing Exchange online Office365 and On premises with the Exchange Management Shell

Marshal HubsEmail Consultant
It has been a great concern for Administrators to manage Exchange online and Exchange On Premises. A Windows PowerShell technology, Exchange Management Shell facilitates the task. The shell allows you to manage every important aspect of Exchange, including enabling email accounts, configuring database properties, creating send and receive connectors, etc. Below are some important tips to use PowerShell for managing Exchange Online in Office365.

Connecting to Exchange Online

You can easily connect to Exchange Online using Remote Powershell. To do so, follow the given steps:
Launch Windows Powershell and execute the following:
$UserCredential = Get-Credential
Provide the username and password of the account through which you need to connect to Exchange Online in the Windows Powershell Credential Request dialog. Click 'OK'.

If you specify incorrect username or password, you may receive the following message:

Connecting to remote server failed with the following error message : Access is denied.

Run the given command to create a new connection to the Exchange Client Access Server.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection

Execute the following to import all commands in this session:

Import-PSSession $Session

Here, you need to run Import-PSSession cmdlet; but before running it, check whether you have permission to run the scripts. If the following message displays when you run the script, you need to enable the execution of scripts.

File skipped because of the following validation except
ion: File ~\Temp\tmp_ab665a-4654-3684-3d32b_cuwqdhef.gqv\tmp_7465acc6-7657-85bb54d7f55g_fdfgtrsd.gqv.format.ps1xml cannot be loaded because the execution of scripts is disabled on this system.

For enabling the scripts execution, you need to run the Set-ExecutionPolicy Unrestricted cmdlet. Moreover, the parameter AllowRedirection uses different URI and allows redirection to an appropriate Exchange server.

Using '-Prefix' for connecting to Exchange Online and Exchange On Premises Simultaneously

To connect to Client Access Server in Exchange On Premises using Remote PowerShell, you launch Exchange Management Shell. It can be seen when you run Get-PSSession after launching the Exchange Management Shell. When you try creating a new persistent connection to Exchange Online, you may get the following warning message:

“WARNING: Proxy creation has been skipped for the following command: …., because it would shadow an existing local command. Use the AllowClobber parameter if you want to shadow existing local commands.”

As directed by the message, if AllowClobber parameter is used, you wil end up replacing the existing commands. To resolve the problem, you can use the parameter Prefix. This adds a prefix to the names of imported commands, which helps prevent shadowing the existing commands. Run the command as follows:

'Import-PSSession $Session –Prefix AXD'

Here, the prefix is 'AXD'.

Closing PSSessions

Run the cmdlet 'Remove-PSSession'. It will close all the PowerShell sessions (as suggested by name), stop all the commands running in PowerShell sessions, end the sessions, and free all the resources used by PSSession. On the other hand, if the session is connected with a remote system, then also you can use the Remove-PSSession cmdlet to close the connection between remote and local systems. It is necessary to follow the described process because if you do not disconnect from server-side session and close the PowerShell window, you will leave the connection open for 15 minutes and you are allowed to have only 3 connections to server-side session at a time for each account.

Mentioned are the important and useful tips that you can consider. Other than this, you may also use Windows PowerShell profiles.
Marshal HubsEmail Consultant

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.