#Exchange 2013: Gesundheit! 49152 8 Task „Get-HealthReport“ löst einen Ausnahmefehler aus…

OMG, ob Microsoft das jemals reibungslos in den Griff bekommt? Seit einigen Versionen gibt’s ja diesen Health-Manager. Vielleicht will man das ja auch alles gar nicht wissen, sollte man aber. In sofern ist dagegen nichts einzuwenden. Doch Microsoft macht es einem da wirklich nicht einfach. Wenn Dir diese Meldung im Topic auf den Zünder geht, hab‘ ich da was für Dich. Und Du solltest Dich drum kümmern.

Zunächst einmal, die Meldung lautet wie folgt:

MSExchange_CmdletLogs (PID 7288, Thread 34) Task "Get-HealthReport" löst einen Ausnahmefehler aus: System.ArgumentException: sessionState bei Microsoft.Exchange.Configuration.Tasks.ExchangePropertyContainer.GetProvisioningBroker(ISessionState sessionState) bei Microsoft.Exchange.Provisioning.ProvisioningLayer.GetProvisioningHandlersImpl(Task task) bei Microsoft.Exchange.Provisioning.ProvisioningLayer.GetProvisioningHandlers(Task task) bei Microsoft.Exchange.Configuration.Tasks.Task.<BeginProcessing>b__4() bei Microsoft.Exchange.Configuration.Tasks.Task.InvokeNonRetryableFunc(Action func, Boolean terminatePipelineIfFailed).")

TL-DR/Bedeutung: Die Health-Mailboxen sind höchstwarscheinlich hinüber. Mach‘ Tabularasa.

Bevor Du das tust, solltest Du aber einige Dinge abklären. Primär solltest Du also wirklich wissen, ob alles in Ordnung ist, mit Deiner Mühle. Also kannst Du sie fragen:

Get-ServerHealth $env:computername | ? AlertValue -ne Healthy | ft Name,HealthSetName,ServerComponentName,AlertValue -AutoSize

und bekommst passende Antworten:

In meinem Fall wird sich das Thema RSS auf einem HyperV2008R2 Wirt z.B. niemals lösen lassen ;-)

Wichtig zu wissen ist auch, ob die Servercomponents alle gesund sind:

Get-ServerComponentState $env:computername

und Du bekommst passende Antworten:

Wenn dem alles so ist, und die Hütte ist gesund, liegt es womöglich an kaputten Health-Mailboxen. Die kannst Du neu erstellen lassen. Am einfachsten geht es mit einem Script, welches Thomas Windscheif freundlicherweise gebastelt hat, um Dir die Last abzunehmen. Meine Empfehlung und Hochachtung – Funktioniert prima:

.\Recreate-Healthmailboxes.ps1 -ExchangeFQDN DeinExchangeFQDN

Und die o.g. Fehlermeldung sollte bald Geschichte sein.

Der Sicherheit halber, weil Webseiten gerne mal verschwinden, schreib‘ ich das Ding nochmal kurz auf.

<#
.NOTES
	Name: Recreate-Healthmailboxes.ps1
	Author: Thomas Windscheif / Microlinc
	Requires: Access to Exchange Remote PowerShell
	Homepage: http://microlinc.homeip.net/index.php?lev1=25&lev2=8&lev3=&id=329
	Version History:
	1.0 - 3/24/2016 - Initial Release
.SYNOPSIS
	Stops Exchange Health Manager Service on all Exchange Servers and then
	disables all HealthMailboxes. Depending on your choice the Script will wait for you until you
	delete the corresponding AD-Objects or the script will delete the Objects automatically.
.DESCRIPTION
	The Script first tries to load Active Directory-PowerShell-Module then it trie to establish a
	Exchange Remote PowerShell-Session to the prior defined Exchange Host.
	After establishing a connection it retrieves a List of Exchange servers with AdminDisplayVersion equal
	or greater than 15 (^= Exchange 2013). The Service MSExchangeHM is stopped on those hosts.
	Now all Monitoring Mailboxes are going to be disabled.
	Depending on your choice (RemoveADObjects) ADObjects are deleted automatically or you remove them manually.
	At the End all MSExchangeHM-Services on all Exchage-Hosts are getting started againn.		
.PARAMETER RemoveADObjects
	The Switchparameter RemoveADObjects defines whether you want to delete the AD-Objects manually or if set,
	they are deleted automatically. Default Setting is: manual removal.
.PARAMETER ExchangeFQDN
	This Parameter is mandatory. It defines the FQDN of the Exchange-Server which is used to establish
	the Remote Powershell-Session.
.EXAMPLE
	[PS] C:\>.\Recreate-Healthmailboxes.ps1 -ExchangeFQDN MSX-01.yourdomain.tld
.EXAMPLE
	[PS] C:\>.\Recreate-Healthmailboxes.ps1 -ExchangeFQDN MSX-01.yourdomain.tld -RemoveADObjects
#>


[CmdletBinding()]
Param(
[switch]$RemoveADObjects = $false,
[Parameter(Mandatory=$true)]
[string]$ExchangeFQDN
)

if (!(Get-Module "ActiveDirectory")) {
	try {
		Import-Module "ActiveDirectory" -ErrorAction Stop
	} catch {
		Write-Error "Loading ActiveDirectory-Module failed!"
		return
	}
}

Write-Host "Establish Remote Exchange-Powershell-Session through $ExchangeFQDN"
try {
	$EXPSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$ExchangeFQDN/PowerShell -ErrorAction Stop
	} catch {
	Write-Error "Establishing a Remote-PowerShell-Session failed!"
	return
	}

Write-Host "Retrieve Exchange-Server-List.."
$ExchangeServers = Invoke-Command -Session $EXPSSession -Command {Get-ExchangeServer}
#Returns only Exchange-Server greater or equal Exchange 2013
$ExchangeServers = $ExchangeServers | ? {$_.AdminDisplayVersion -match "^Version 15"}

if ($ExchangeServers -eq "" -or $ExchangeServers -eq $null) {
Write-Error "No Exchange Server retrieved"
} else { 
	Write-Host "The following Exchange Servers were found:"
	$ExchangeServers.fqdn
	Write-Host "Stopping HealthManager Service on all Exchange Servers"
	foreach ($ExchangeHost in $ExchangeServers) {
		try {
			Invoke-Command -Computername $ExchangeHost.fqdn -Command {Stop-Service "MSExchangeHM"} -ErrorAction Stop
		} catch  {
			Write-Error "Stopping $($ExchangeHost.fqdn) failed!"
		}
	}

	Write-Host "Wait a moment.."
	sleep 2 

	Write-Host "Disable Healthmailboxes"
	Invoke-Command -Session $EXPSSession -Command {Get-Mailbox -Monitoring | Disable-Mailbox -Confirm:$false}

	if ($RemoveADObjects -eq $true) {
		Write-Host "Remove AD-Objects in CN `"Microsoft Exchange System Objects`""
		$ADObjectsHM = Get-ADObject -Filter 'objectclass -eq "user"' -SearchBase "CN=Monitoring Mailboxes,CN=Microsoft Exchange System Objects,$((Get-ADRootDSE).DefaultNamingContext)" -properties Name | ? {$_.Name -match "^HealthMailbox"}
		foreach ($ADObject in $ADObjectsHM) {
			try {
				#Recursive is needed, because of nested Objects like Exchange Active-Sync-testobjects
				Remove-ADObject $ADObject -Recursive -Confirm:$false -ErrorAction Stop
				Write-Host "$($ADObject.Name) deleted !"
			} catch {
				Write-Error "Failed to Delete AD-Object $($ADObject.Name)" 
			}
		}
	} else {
		write-host "Move or Remove old Mailbox-AD-Objects in `"Microsoft Exchange System Objects`" > `"Monitoring Mailboxes`""
		$input = "n"
		while ($input -ne "y") {
			$input = read-host "Task finished? (y/n)"
		}
	}

	Write-Host "Start HealthManager Service on all Exchange Servers"
	foreach ($ExchangeHost in $ExchangeServers) {
		try {
			Invoke-Command -Computername $ExchangeHost.fqdn -Command {Start-Service "MSExchangeHM"} -ErrorAction Stop
		} catch {
			Write-Error "Failed to Start HealthManager Service on $($ExchangeHost.fqdn)"
		}
	}
}

Write-Host "Remove PowerShell-Session"
Remove-PSSession -Session $EXPSSession