A Blog on Wndows Server and Microsoft Exchange by Thomas Pätzold

Posts Tagged ‘Monitoring

Advanced Mailboxstatistics

leave a comment »

As an administrator of a large Exchange System you have configured a mailboxquota for each mailbox. But the interesting question is what is the ratio between the configured quota and the used mailboxstore. In order to get this value you have to create your own Windows Powershell function.

The following function enumerates all data and stores it in a custom object. So you are able to work with this object.

function get-mailboxquotausage {
	This function enumerates the configured quota and used mailboxstore for each mailaddress
	of a maildomain. The user is able to specify the maildomain as a parameter to this function.
	This script enumerates all mailaddresses from one primary maildomain. Displayname, primary SMTP address, prohibit send quota and the used mailboxstore are displayed.
.PARAMETER Maildomain
	This parameter specifies the maildomain this function will work on.
	get-mailboxquotausage -maildomain
	This command will show the displayname, primary SMTP address, prohibit send quota and used mailboxstore for the domaine
	get-mailboxquotausage -maildomain | select displayname, @{label="size (MB)"; expression={"{0,0:N0}" -f $_.size}}, @{label="quota (MB)"; expression={"{0,0:N0}" -f $_.quota}}

	This command will show the displayname, primary SMTP address, prohibit send quota and used mailboxstore for the domaine
	The displayed values will be displayed with a decimal point according to the configured language setting.

param([Parameter(Mandatory=$True, ValueFromPipeline=$True)][string]$maildomain)

begin {

$delete = 0
$result = @()
$users=get-mailbox |? {$_.primarysmtpaddress -like "*$maildomain*"}

foreach ($user in $users) {

	$userstats=Get-MailboxStatistics $user 

	$obj=new-object psobject
	$obj = @{}
	$obj.add("Displayname", $user.displayname)
	$obj.add("Mailaddress", $user.primarysmtpaddress)
	write-host $user.primarysmtpaddress
	if (-not $user.prohibitsendquota.isunlimited) {
		$obj.add("Quota", ($user.prohibitsendquota.value.toMB()))
	} else {
		$obj.add("Quota", "unlimited")
	$obj.add("Size", ($userstats.totalitemsize.value.toMB()))
	$result += new-object -type PSObject -Property $obj



Written by Thomas Pätzold

January 28, 2013 at 9:40 pm

Monitoring Microsoft Exchange 2010 with NAGIOS

with 2 comments

If you want to monitor your Microsoft Exchange 2010 environment you have to choose a client which communicates with the NAGIOS Server. A popular client application is NSCLIENT++. If you want to monitor your Exchange System it is necessary to write your own monitoring script which is executed on the monitored system. In order to do so you can use the NRPE (Nagios Remote Plugin Executor) Plugin which is supported by NSCLIENT++.

Each output of the script will be displayed by NAGIOS. So the first challenge is to start the Exchange Shell without any status output. After this you can script your monitoring algorithm. At the end of the script you have to exit this script with the exit code.

value description
0 no error
1 Warning
2 Error

The following script monitors the status of a mailbox database. If the status isn´t healthy or mounted the script will return an error and NAGIOS itsself will display this Service as not available or red.

# initialisiere Exchangeumgebung
$s = new-pssession -configurationname -connectionuri -authentication Kerberos
$warningpreference = "SilentlyContinue"
Import-PSSession $s 2>&1 | out-null

##### MAIN #####
# variabledeklaration

$MailboxDatabases = Get-MailboxDatabaseCopyStatus
foreach ($mailboxdatabase in $mailboxdatabases) {
	switch ($mailboxdatabase.Status) {
		Healthy {$healthy += " " + $mailboxdatabase.Identity}
		Mounted {$mounted += " " + $mailboxdatabase.Identity}
		Default {$errorvalue=2;	$errortext += "Not Mounted or Healthy: " + $mailboxdatabase.Identity}
if ($mounted.length -eq 0) {$mounted="-"}
if ($healthy.length -eq 0) {$healthy="-"}
$errortext += "Mounted: "+$mounted + "Healthy: "+$healthy
write-output $errortext
exit $errorvalue

Written by Thomas Pätzold

January 6, 2011 at 9:31 pm

Start the Microsoft Exchange 2010 Shell

leave a comment »

Since Exchange 2007 Windows Powershell is used in order to administer the Microsoft Exchange environment. In order to use the shell you start the Exchange Management shell. It looks like

Exchange 2010 Shell

In some scenarios it might be useful to be able to start the Exchange shell without the verbose messages indicating to whitch Exchange Server the shell is connected to. In order to do this you have to load the Exchange Shell extensions in a normal Windows Shell Session. In order to do this you have to run the following commands in the PowerShell:

$s = new-pssession -configurationname -connectionuri "" -authentication Kerberos
$warningpreference = "SilentlyContinue"
Import-PSSession $s 2>&1 | out-null

Now we look a litte bit further. The variable $warningpreference defines what happens if a script uses the write-warning cmdlet in order to make some output. If you set this variable to the value of silentlycontinue the output is suppressed. The default of this variable is Continue whitch means that warningmessages are displayed in yellow color on the console. If you want to get more details on preference variables you can read the PowerShell help

get-help about_preference_variables 

But what does 2>&1 mean? It´s the redirect for the standard error output.  The Standard error is redirected to the standard output and everything is redirected to out-null. So nothing will be shown in the end and the Powershell with Exchange extensions looks like.

Now you are able to use 626 Exchange 2010 Commands in your Powershell Session.

Written by Thomas Pätzold

December 30, 2010 at 5:29 pm

%d bloggers like this: