Quantcast
Channel: Practical 365
Viewing all articles
Browse latest Browse all 506

Test-ExchangeServerHealth.ps1 v1.09 is Now Available

$
0
0

I’m pleased to announce the availability of v1.09 of the Test-ExchangeServerHealth.ps1 script.

This version of the script contains one minor bug fix for database availability group member replication health reporting in mixed Exchange 2010/2013 organizations.

Existing Exchange Server Pro Insiders can download the script here. If you are not already a member you can join for free here.

The issue that is fixed was an error when running Test-ReplicationHealth from an Exchange 2013 server against an Exchange 2010 server. Little bugs like this have appeared before in the Test-* cmdlets that ship with Exchange 2013. I fix them as best I can but there is clearly going to be more long term benefit in leveraging Managed Availability in future scripts, as I mentioned here. Still, as long as I am able to I will keep patching the scripts to work in as many on-premises organizations as possible.

Here is an example of Test-Replicationhealth run against an Exchange 2013 server and then an Exchange 2010 server.

[PS] C:\>Test-ReplicationHealth ex2013srv1
Server          Check                      Result     Error
------          -----                      ------     -----
EX2013SRV1      ClusterService             Passed
EX2013SRV1      ReplayService              Passed
EX2013SRV1      ActiveManager              Passed
EX2013SRV1      TasksRpcListener           Passed
EX2013SRV1      TcpListener                Passed
EX2013SRV1      ServerLocatorService       Passed
EX2013SRV1      DagMembersUp               Passed
EX2013SRV1      ClusterNetwork             Passed
EX2013SRV1      QuorumGroup                Passed
EX2013SRV1      DatabaseRedundancy         Passed
EX2013SRV1      DatabaseAvailability       Passed
EX2013SRV1      DBCopySuspended            Passed
EX2013SRV1      DBCopyFailed               Passed
EX2013SRV1      DBInitializing             Passed
EX2013SRV1      DBDisconnected             Passed
EX2013SRV1      DBLogCopyKeepingUp         Passed
EX2013SRV1      DBLogReplayKeepingUp       Passed
[PS] C:\>Test-ReplicationHealth ho-ex2010-mb1
Could not load file or assembly 'Microsoft.Exchange.Data, Version=14.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
    + CategoryInfo          : NotSpecified: (:) [Test-ReplicationHealth], FileNotFoundException
    + FullyQualifiedErrorId : [Server=EX2013SRV1,RequestId=a14edcd8-cd42-4cb3-9af7-0140d97babef,TimeStamp=7/07/2014 12
   :52:02 PM] [FailureCategory=Cmdlet-FileNotFoundException] 864218C8,Microsoft.Exchange.Monitoring.TestReplicationHe
  alth
    + PSComputerName        : ex2013srv1.exchangeserverpro.net

To work around this issue I’ve added a function to the script that will detect the error and create a PSSession to an Exchange 2010 CAS in the same site as the mailbox server that Test-ReplicationHealth is being run against. The test can then be performed by the Exchange 2010 server instead.

[PS] C:\Scripts\TestReplicationHealth>.\Test-E14ReplicationHealth.ps1 ho-ex2010-mb1 -Verbose
VERBOSE: Get replication health for ho-ex2010-mb1
VERBOSE: Error, trying workaround
VERBOSE: Creating PSSession for HO-EX2010-MB1.exchangeserverpro.net
VERBOSE: Using URL http://ho-ex2010-mb1.exchangeserverpro.net/powershell
VERBOSE: Running replication health test on ho-ex2010-mb1
VERBOSE: Removing PSSession
VERBOSE: ClusterService Passed
VERBOSE: ReplayService Passed
VERBOSE: ActiveManager Passed
VERBOSE: TasksRpcListener Passed
VERBOSE: TcpListener Passed
VERBOSE: ServerLocatorService Passed
VERBOSE: DagMembersUp Passed
VERBOSE: ClusterNetwork Passed
VERBOSE: QuorumGroup Passed
VERBOSE: FileShareQuorum Passed
VERBOSE: DBCopySuspended Passed
VERBOSE: DBCopyFailed Passed
VERBOSE: DBInitializing Passed
VERBOSE: DBDisconnected Passed
VERBOSE: DBLogCopyKeepingUp Passed
VERBOSE: DBLogReplayKeepingUp Passed

Here is the sample code. Note that this is for demonstration purposes and is not intended to be a working script. The function has been incorporated into Test-ExchangeServerHealth.ps1.

#requires -version 2
[CmdletBinding()]
param (
    [Parameter( Mandatory=$true)]
	[string]$Server
)
#This function is used to test replication health for Exchange 2010 DAG members in mixed 2010/2013 organizations
Function Test-E14ReplicationHealth()
{
	param ( $e14mailboxserver )
	$e14replicationhealth = $null
    $ADSite = (Get-ExchangeServer $e14mailboxserver).Site
    $e14cas = (Get-ExchangeServer | where {$_.IsClientAccessServer -and $_.AdminDisplayVersion -match "Version 14" -and $_.Site -eq $ADSite} | select -first 1).FQDN
	Write-Verbose "Creating PSSession for $e14cas"
    $url = (Get-PowerShellVirtualDirectory -Server $e14cas -AdPropertiesOnly | Where {$_.Name -eq "Powershell (Default Web Site)"}).InternalURL.AbsoluteUri
    if ($url -eq $null)
    {
        $url = "http://$e14cas/powershell"
    }
    Write-Verbose "Using URL $url"
	try
	{
	    $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $url -ErrorAction STOP
	}
	catch
	{
	    Write-Verbose "Something went wrong"
		if ($Log) {Write-Log $_.Exception.Message}
    	Write-Warning $_.Exception.Message
	}
	try
	{
	    Write-Verbose "Running replication health test on $e14mailboxserver"
	    $e14replicationhealth = Invoke-Command -Session $session {Test-ReplicationHealth} -ErrorAction STOP
	}
	catch
	{
	    Write-Verbose "An error occurred"
		if ($Log) {Write-Log $_.Exception.Message}
	    Write-Warning $_.Exception.Message
	}
	Write-Verbose "Removing PSSession"
	Remove-PSSession $session.Id
	return $e14replicationhealth
}
try
{
    Write-Verbose "Get replication health for $server"
    $replicationhealth = $server | Invoke-Command {Test-ReplicationHealth -ErrorAction STOP}
}
catch
{
    Write-Verbose "Error, trying workaround"
    $replicationhealth = Test-E14ReplicationHealth $server
}
foreach ($healthitem in $replicationhealth)
{
    $tmpstring = "$($healthitem.Check) $($healthitem.Result)"
	Write-Verbose $tmpstring
	if ($Log) {Write-Logfile $tmpstring}
}

This article Test-ExchangeServerHealth.ps1 v1.09 is Now Available is © 2014 ExchangeServerPro.com

Get more Exchange Server tips at ExchangeServerPro.com


Viewing all articles
Browse latest Browse all 506

Trending Articles