I want to output results using Write-host "Message.SOMETHING" and write-host "Statistic.SOMETHING" inside of a foreach loop, but I find that it's very difficult to get it right.
Here's an except from the script:
############################################
$counter = 0
foreach ($item in $events_list) {
$message = "`n- Severity: $($item.severity)`n- Summary: '$($item.name)'`n- Explanation: $($item.cause)`n- Location: $($item.resource_name)`n"
$counter++
Write-Host "Message.NEWEVENT$($counter): $message"
#Write-Host "Statistic.NEWEVENT$($counter): $($events.Count)"
}
############################################
This give me Message outputs as I want (with several results below the pasted event), however it fails (from which I understand is because there's no corresponding statistic).

However, when I remove the Hash comment from the code above and enable the line "Write-Host "Statistic.NEWEVENT$($counter): $($events.Count)", I get the following results:

Can anyone tell me why I am getting N/A in the message.NEWEVENT when enabling the statistic?
Any help is appreciated!