Get DAG Database Distribution Function

PowerShell is great for repeatable administration shortcuts. I had created a script to a while ago that provided the mounted database distribution on each Database Availability Group server as part of a larger routine status reporting script. I found that this particular task of know the database distribution during the business day was helpful so I converted it to a function and included into my PowerShell profile. That way I could just run the Get-DagDbCount function without hunting around my various scripts directories trying find it and run it in script form.

It is really quite simple and makes use of an empty array populated with custom PSObjects with just server name and the number of mounted databases on it. Comments in the script should make everything clear on what is happening.

# Initialize function name.
Function Get-DagDbCount {
	# Return the status of all mailbox database copies.
	$DAGDbs = Get-MailboxDatabaseCopyStatus *
	# Return the DAG in the organization
	$Dag = Get-DatabaseAvailabilityGroup
	# Create empty array to hold DAG data.
	$DagTable = @()
	# Pipe the DAG members to a foreach-object loop to count mounted Dbs for each server. Then add
	#  results to array.
	$Dag.servers | foreach {
		$DagServerName = $_.Name
		$DagObject = New-Object PSObject
		$DagObject | Add-Member -type NoteProperty -Name "Server" -Value $DagServerName
		$DagObject | Add-Member -type NoteProperty -Name "MountedDbCount" `
		-Value (($DAGDbs | where {$_.mailboxserver -eq $DagServerName -and $_.status -eq "mounted"}) | measure).count
		$DagTable += $DagObject
	# Show results to screen.


Using Search-Mailbox -SearchQuery

I had recently been given the task to search all mailboxes in an Exchange 2013 on premises organization for a specific keyword phrase. Naturally I attempted to use the eDiscovery and Litigation hold feature of the EAC but was severely limited by the number of mailboxes I could search at one time. As always I’m looking for a way to automate time consuming tasks. The PowerShell cmdlet New-MailboxSearch also didn’t help much either. After submitting a new search I attempted to view the status and I get a Watson error.


Enter the older but tried and true Search-Mailbox cmdlet. It took me a while to figure out how to use the -SearchQuery switch though. I had checked through the documentation on how to do Exchange Search using the Advanced Query Syntax (AQS) but nothing was very clear on my problem.

Read moreUsing Search-Mailbox -SearchQuery

Recover from an Email Storm in Exchange Server

An important part of working with Exchange server is being prepared for and dealing with an email storm.  The term email storm has been associated with reply all behavior and NDR message loops.  An email storm can also be the result of a virus or worm infection causing a large number of messages to be sent within your Exchange organization.

Read moreRecover from an Email Storm in Exchange Server