In part one of this series, we discussed the basics of PowerShell. In part 2, we'll discuss how you can incorporate PowerShell with SAM to build a more effective monitoring solution.
PowerShell Templates and Monitors
Many SAM templates contain component monitors that allow for the use of PowerShell scripts. An easy way to find a list of these templates is to navigate to the Manage Application Monitor Templates page and search for the word, "PowerShell." This can be done from the SAM web console by navigating to Settings > SAM Settings > Manage Templates. The search text box is at the top-right of the screen.
Below is a sample list of the templates found when "PowerShell" is searched. To examine and edit a template, check the box next to the template name. Once a template is checked, the Edit button will become enabled. Click Edit at the top of the list to open the selected template.
The PowerShell Template
In this example, the Exchange 2007-2010 Mailbox Send and Receive Statistics with PowerShell template is used. This template tracks Exchange Mailbox Send/Receive statistics of Exchange 2007-2010 servers with the Mailbox role using PowerShell scripts. The following screen appears once you have selected a template to edit, revealing the individual component monitors as well as details about the template:
The following documentation accompanies this template:
• PowerShell 2.0 and Exchange Management Tools 2007 or 2010 installed on the SAM server.
• The Exchange server must have an Exchange Mailbox role.
• The SAM server and the Exchange server must be in the same domain.
The credentials must be an Exchange Administrator (Organization Manager) account with at least view-only permissions.
Note: Before using this template, under the Advanced tree collapse [+], you should set the correct platform; either 32-bit or 64-bit, from the dropdown menu. The default it set to 32-bit.
For all PowerShell component monitors: You must specify the correct name of your Exchange user and server in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status.
For example: If the name of your Exchange server is exchange.mydomain.com, and the user you want to monitor is firstname.lastname@example.org, the value in the Script Arguments field should be the following: email@example.com,exchange.mydomain.com.
To see the names of your Exchange servers, run the following PowerShell command in the Exchange Management Shell: Get-ExchangeServer
To see the names of the users, run the following PowerShell command in Exchange Management Shell: Get-Mailbox
The Component Monitor
To examine and edit an individual PowerShell component monitor within the template, click the plus sign [+] to the left of the monitor.
For example: Number of items received by specific user during last month.
The following details about the selected component monitor are revealed:
Using a PowerShell script, the monitor in this example is designed to return the number of items received by a specific user during the last month. In order to use this monitor, you will need to change the Script Arguments field from the default example of, firstname.lastname@example.org,server.domain.sw to something that will suit your needs for your particular environment. You can do this by clicking the Edit button (highlighted above).You also have the ability to alter the pre-defined script that comes with PowerShell component monitors.
Note: Unless otherwise directed by the documentation, you should not need to edit pre-defined scripts.
Once you have changed the Script Arguments field, click Submit to begin using the component monitor within the template. The output for this script using the SAM monitor, Number of items received by specific user during last month, should be similar to the following illustration:
The output for the script using only PowerShell should be similar to the following illustration:
In the next of this series, we'll discuss PowerShell Code with SAM.