Hi Mike - thanks for this script.
I think I may have tripped across an issue running in -Gather mode with "-MonitoringExchange2013 $false".
I was getting a lot of "You cannot call a method on a null-valued expression." errors followed by "ERROR: Failed to read perfmon counter from server xxxxxxx." However, I was getting data in LogStats.csv from the first (and only the first) server listed in TargetServers.txt. I verified that I could run a Perfmon query against all servers with the "Get-Counter -ComputerName COMPUTERNAME" suggestion. I also re-ordered the servers in TargetServers.txt and still only got stats from the first (but different) server listed. Since I only have Ex2010 servers I was dutifully running with the "-MonitoringExchange2013 $false" parameter.
I think I've traced the issue down to the following section of the GetLogGenerations function:
…
if ($MonitoringExchange2013 -eq $true)
{
$allCounters = Get-Counter -ListSet "MSExchangeIS HA Active Database" -ComputerName $serverName -ErrorAction SilentlyContinue
}
#Either we failed to connect to the server, or this isn't a 2013 server. Try the 2007/2010 command.
if ($allCounters -eq $null)
{
$allCounters = Get-Counter -ListSet "MSExchange Database ==> Instances" -ComputerName $serverName -ErrorAction SilentlyContinue
}
else
{
$is2013Server = $true
}
…
The first time through the "foreach ($server in $targetServers)" loop, the counters are gathered as expected. However, for each subsequent server, since $MonitoringExchange2013 is $false AND $allCounters is never being "cleared out" (i.e. it's not $null), Get-Counter is never being run against the other servers. Subsequent filtering ends up leaving $targetCounters empty, ultimately resulting in the "Failed to read perfmon counter…" error.
To test this, I ran with $MonitoringExchange2013 set to $true (the default) and output for all servers was added to LogStats.csv. Since I wanted the performance increase gained with $MonitoringExchange2013 set to $false, I added the following line just above the aforementioned block of code.
$allCounters = $null
That seemed to do the trick…