References > Aliases > PowerShell and SAM: Configuration and Usage

PowerShell and SAM: Configuration and Usage

In order to use PowerShell with SAM you must have PowerShell 2.0 installed on the SAM and target servers. PowerShell 2.0 can be found here: http://support.microsoft.com/kb/968930

Once PowerShell is installed on the SAM and target servers, ensure that Windows Remote Management (WinRM) is properly configured and enabled on the SAM and target servers. To do this, follow these steps:

  1. On the SAM server, open a command prompt as an Administrator. To do this, go to the Start menu and right-click the Cmd.exe and then select Run as Administrator.
  2. Enter the following in the command prompt:
    winrm quickconfig –qwinrm set winrm/config/client @{TrustedHosts="*"}
  3. On the target server, open a command prompt as an Administrator and enter the following:
    winrm quickconfigwinrm set winrm/config/client @{TrustedHosts="IP_ADDRESS"}

where IP address is the IP address of your SAM server. Once you have successfully completed these steps, PowerShell will be able to properly communicate with SAM.

Exchange 2010 Management Tools

Many SAM PowerShell components rely on Exchange Management Tools. Both the 2007 and 2010 editions are acceptable.

If you plan to monitor Exchange 2007 then you must use the Exchange 2007 Management Tools. If you plan to monitor Exchange 2010 then you will need to install the Exchange 2010 Management Tools.

Exchange Management Tools must be installed on the SAM server and any additional poller that will poll using PowerShell scripts. Any snap-ins that PowerShell may require must also be installed in the same location.

To ease PowerShell plug-in management in a multi-poller environment, you may prefer to assign nodes with PowerShell templates to a single polling engine.

Exchange 2010 Management Tools will be used for the following instructions:

Installation of Exchange Management Tools:

To install Exchange Management Tools on your Windows computer, you first need to configure the pre-requisite components.

  1. Open the Control Panel, click on Programs and then click Turn Windows Features On or Off.
  2. Enable the features shown below:
  1. Download the Exchange Server 2010 SP1 installation files and extract them to a temporary folder on your computer.  
  2. From that folder launch Setup.exe.  (If your computer is missing the .NET Framework, visit Microsoft.com to download and install it. Additionally, Steps 1 and 2 of the Exchange Server 2010 SP1 installation will prompt you to install pre-requisites if they are missing, as shown in the following illustration.)
  1. If needed, install the pre-requisites for Exchange Server 2010 SP1. If not, click on Step 3 from the install screen and choose Install only languages from the DVD.
  1. Choose language options for installing Exchange Server 2010 SP1 on Windows.
  2. Next, click on Step 4 from the install screen to begin the installation.
  1. Begin the installation of Exchange Server 2010 SP1 on Windows.
  2. Click Next at the introduction page, then Accept the license agreement.
  3. Click Next, then choose your preference for Error Reporting.
  4. Click Next.
  5. At the Installation Type page, select Custom Exchange Server Installation, and also check the box to Automatically install Windows Server roles and features required for Exchange Server.
  6. Click Next.
  1. Select the Management Tools role and then click Next.

64-bit vs. 32-bit

Using the 64-bit (x64) or 32-bit (x86) version of PowerShell depends on how your target server and applications are configured. Ideally, both machines should be running on the same platform to get the most out of PowerShell.

Platform Scenarios

For the most part, you will not encounter any differences between the 64-bit and 32-bit versions of PowerShell; however, each version of the shell, in some cases, can only load matching snap-ins. This means you should use the correct 64-bit or 32-bit version of any snap-ins you plan to use. Below are some guidelines to help you determine which version of PowerShell you should use for your particular monitoring environment:

  • If SAM is installed on a 64-bit sever and polling a 64-bit machine, you should poll using the 64-bit version of PowerShell.
  • If SAM is installed on a 64-bit sever and polling a 32-bit machine, you should poll using the 32-bit version of PowerShell.
  • If SAM is installed on a 32-bit sever and polling a 32-bit machine, you should poll using the 32-bit version of PowerShell.
  • If SAM is installed on a 32-bit server and polling a 64-bit machine, you may encounter some errors. You should install SAM on a 64-bit server if you need to poll 64-bit machines.

Note: There may be instances where installed software on a 64-bit machine may have added its own cmdlets into the 32-bit version of PowerShell. If this is the case, you should use 32-bit polling.

On Windows machines, you can determine the platform you are using by right-clicking My Computer and clicking Properties.

Troubleshooting PowerShell Snap-In Compatibility

The most common issue with PowerShell is the incompatibility of the snap-ins with the platform of PowerShell being used; meaning both PowerShell and its snap-ins should both be either 64-bit or 32-bit. When running your script in SAM, typical errors of this type resemble the following:

However, no evidence of a snap in problem exists in PowerShell itself.

In order to diagnose and correct this problem, verify that the snap-ins are properly registered by doing the following.

  1. Find the following registry path:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns

    Notice the ApplicationBase path is “C:\Program Files\Microsoft\Exchange Server\bin” not “C:\Program Files (x86)”. The “C:\Program Files (x86)” path would suggest 32-bit PowerShell extensions are registered.

 

  1. Open PowerShell though the GUI and check to see if the process is running in 32-bit mode. This is denoted by the “*32” next to the process name. Since this is a 64-bit server with the 64-bit Exchange Management installed, PowerShell should not have a "*32" next to the process name. It should look similar to the image below:
  1. Open your 64-bit PowerShell session and run the following:
    add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
  2. Run get-PSSnapin –registered. You should see the snap-in listed as shown below:
  1. Now you should be able to execute a PowerShell command such as Get-MailboxDatabase -Server {exchange server hostname} and have it return results similar to the following:
  1. Your snap-in module has properly been registered. SAM templates that use PowerShell will now work properly.