Exchange PowerShell Variables

by [Published on 20 Sept. 2016 / Last Updated on 20 Sept. 2016]

This tip presents the default Exchange PowerShell variables and how we can change these or create new ones.

Since the release of Exchange Server 2007 (the first version to include PowerShell) that the Exchange Management Shell (EMS) includes the following three pre-defined variables:

  • $exbin - contains the full path to Exchange's Bin directory;

  • $exinstall - contains the full path to Exchange's install folder;

  • $exscripts - contains the full path to the Exchange's script folder.

 

In a default installation of Exchange 2016, this is what these variables contain:

 Image

 

These variables are used in different scenarios such as some scripts provided by Microsoft, and can also be used by administrators to facilitate the management of Exchange. But where are these variables defined? Can we add a couple more?

When we load the EMS, the Exchange.ps1 script located in the Bin directory is run. Within this script we can find these variables defined:

$global:exbin = (get-itemproperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup).MsiInstallPath + "bin\"
$global:exinstall = (get-itemproperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup).MsiInstallPath
$global:exscripts = (get-itemproperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup).MsiInstallPath + "scripts\" 

 Image

 

If, for any reason, you would like to add another variable, you can add it here. For example, to add a variable to your Message Tracking Logs directory you could do something like this:

$global:exmsgtl = "E:\Program Files\Microsoft\Exchange Server\V15\TransportRoles\Logs\MessageTracking\"

See Also


The Author — Nuno Mota

Nuno Mota avatar

Nuno is an Exchange MVP working as a Senior Microsoft Messaging Consultant for a UK IT Services Provider in London. He specializes in Exchange, Lync, Active Directory and PowerShell.

Featured Links