sus42

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

Posts Tagged ‘Exchange 2010

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 {
<#
.SYNOPSIS
	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.
.DESCRIPTION
	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.
.EXAMPLE
	get-mailboxquotausage -maildomain aixtest.de
	
	Description
	===========
	This command will show the displayname, primary SMTP address, prohibit send quota and used mailboxstore for the domaine @aixtest.de
	
.EXAMPLE
	get-mailboxquotausage -maildomain aixtest.de | select displayname, @{label="size (MB)"; expression={"{0,0:N0}" -f $_.size}}, @{label="quota (MB)"; expression={"{0,0:N0}" -f $_.quota}}
	

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




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

begin {
}


process{
$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
}
$result
}

end{}

}

Written by Thomas Pätzold

January 28, 2013 at 9:40 pm

Update Exchange 2010 Infrastructure

leave a comment »


If you are running an Exchange environment, it is necessary to plan the upgrade process of both the operating system and the Exchange system carefully in order to prevent data loss.

In order to do this you have to follow the steps below:

  • Virus scan tool, monitoring and Backup
    • First of all you have to check the prerequisits of the other software components such as the virusscanner, monitoring client or backup client. After you have assured that the components you use are working properly with the installed update you should start the upgrade process.
  • CAS Server
    • After you checked the prerequitsits you are able to start the upgrade process of your Exchange Environment. First of all you should start with the internet-facing Client Access Server roles. After this you can start the upgrade process of the intranet Client Access Server. During the upgrade process it might be possible that not all clients are able to connect to the infrastructure. In order to improve this you should consider using an hardware load balancing system.
  • HUB Server
    • After upgrading the Client Access Server you should upgrade your HUB Servers next.
  • Mailboxserver
    • Now it is time to upgrade your Mailbox servers. Please consider, it might be a diffrence, if you use a single server environment or a Mailboxcluster (Database Availability Group). Basically you should start upgrading the Databaseserver which doesn´t hold any active databases.
  • Edge Transport Server
    • After you have upgraded all other Exchangeservers you should upgrade the Edge Transport Server now.

In order to support the upgrade process of the members of a database availability group (DAG) there are two scripts in the installation folder of Exchange 2010 (usually c:\Program Files\Microsoft\Exchange Server\v14\scripts).

Starting the maintenance mode
In order to start the maintenance mode you should use the script StartDagServerMaintenance.ps1
This script

  • pauses the node so that it couldn´t become the Primary Active Manager
  • suspends database activation on the specified node
  • moves the active database of the designated server to another Mailboxserver in the same DAG

After maintenance is finished you must stop the maintenance mode manually in order to reactivate the specified mailboxserver.

Stopping the maintenance mode
In order to stop the maintenance mode you should use the script StopDagServerMaintenance.ps1. Consider that stopping the maintenance mode dosn´t move the active copy to the prefered Mailboxserver.

Redistribute Active Mailboxdatabase
If you create a new mailboxdatabase in the DAG then you are able to configure the ActivationPreference attribuite of each mailboxdatabase. Based on this setting you are able to move the active mailboxdatabase to its prefered mailboxserver. In order to redistribute the mailboxdatabase use the following script RedistributeActiveDatabases.ps1.

Written by Thomas Pätzold

January 24, 2012 at 9:59 pm

The Exchange 2010 Powershell SnapIns

leave a comment »


Applies to Exchange 2010 SP1

If you start the Exchange Management Shell, a Powershell instance is started and the Powershell remoting feature is used in order to establish a connection to the Exchange Server System. There is another option to load the Exchange 2010 specific commands in Powershell. In this case you have to start the Powershell and load the necessary Exchange 2010 management snapins.

The following three Exchange 2010 Snapins are available

Microsoft.Exchange.Management.PowerShell.E2010
Microsoft.Exchange.Management.PowerShell.Setup
Microsoft.Exchange.Management.Powershell.Support

In order to load the snapins you are able to use the following command

add-pssnapin -Name Microsoft.Exchange.Management.PowerShell.E2010

If you are writing a Powershell script, it might be useful to check if the plugin is loaded. In order to do this you are able to use the following code snipset.

if (! (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) )
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:Stop
}

What is the difference between the Exchange Management Shell and adding the Exchange snapin to the Powershell session?

  1. The Exchange commands using the Exchange Management Shell are implemented as functions. If you load the “Microsoft.Exchange.Management.PowerShell.E2010” snapin instead of using the Exchange Management Shell the commands are implemented as cmdlets.
  2. Using the Exchange Management Shell you are able to take a more detailed look at how the functions better called the wrapper functions are implemented by using the command.
    get-command get-mailbox -detailed | select-object scriptblock
    

  3. There is one more important diffrence. If you want to use the systemvariable $? it is better to use the loaded snapin instead of the Exchange Management Shell because these commands don´t work properly in the Exchange Managemnt Shell. A second problem is the use of the common parameters because they are not implemented for all functions in Exchange Management Shell.

If you want to start an Exchange Shell Session because you want to execute your command on a special Exchange Server then this is possible but keep the limitations of the Exchange Management Shell in mind.

Written by Thomas Pätzold

September 14, 2011 at 9:10 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 microsoft.exchange -connectionuri http://mbx.aixtest.de/PowerShell/ -authentication Kerberos
$warningpreference = "SilentlyContinue"
Import-PSSession $s 2>&1 | out-null

##### MAIN #####
# variabledeklaration
[system.string]$errortext=""
[system.Byte]$errorvalue=0
[System.string]$mounted=""
[System.string]$healthy=""

$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 microsoft.exchange -connectionuri "http://aixtest-cas.aixtest.de/PowerShell/" -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: