Showing results for 
Search instead for 
Did you mean: 
Create Post

The Basics of PowerShell (part 2)

Level 15

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, and the user you want to monitor is some.user@domain.sw, the value in the Script Arguments field should be the following: some.user@domain.sw,

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, user@domain.sw,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.

Level 15

Very interesting post.  Power Shell!  Power Shell!

Level 7

Hi great post

Hii you are providing good information. Thanks for sharing AND Data Scientist Course in Hyderabad, Data Analytics Courses, Data Science Courses, Business Analytics Training ISB HYD Trained Faculty with 10 yrs of Exp

About the Author
Who am I? • I met Robert Frost at the end of the road less traveled, and then pointed him in the right direction. • Einstein asked me to define "Up," and I did. • I cliff dive from airplanes. • On Christmas, Santa comes to me for gifts. • I play three-cushion billiards with one hand. • Lions ask for my protection (I speak Lion). • Bobby Fischer and I came to a stalemate while playing chess. • I have literally given a woman the shirt off of my back. • I have also helped an old lady cross the street. • I know what a dangling participle is. • Mozart bequeathed his Requiem to me, and I corrected it. • I was thrown out of an Eric Clapton concert twice in the same night for drawing too much attention to myself. • I am a verbose minimalist. • I am Bronx. Who are you?