I use something like
while(condition) {
Get-Counter -computer c 'asp.net\request wait time',.....,`
'.NET CLR Memory(w3wp)\# Total reserved Bytes',
'.NET CLR Memory(w3wp)\# Bytes in all Heaps',
'.NET CLR Memory(w3wp)\% Time in GC',
'.NET CLR Memory(w3wp)\# Induced GC',
'.NET CLR Memory(w3wp)\Allocated Bytes/sec',
'.NET CLR Memory(w3wp)\Finalization Survivors',
'.NET CLR Memory(w3wp)\Large Object Heap size',
'.NET CLR Memory(w3wp)\Gen 2 heap size',
'.NET CLR Memory(w3wp)\Gen 1 heap size',
'.NET CLR Memory(w3wp)\Gen 0 heap size',
'.NET CLR Memory(w3wp)\Promoted Finalization-Memory from Gen 0',
'.NET CLR Memory(w3wp)\Promoted Memory from Gen 1',
'.NET CLR Memory(w3wp)\Promoted Memory from Gen 0',
'.NET CLR Memory(w3wp)\# Gen 2 Collections',
'.NET CLR Memory(w3wp)\# Gen 1 Collections',
'.NET CLR Memory(w3wp)\# Gen 0 Collections'
}
I get several samples and then errors is returned
Get-Counter : The \\c\.NET CLR Memory(w3wp)\# Gen 0 Collections
performance counter path is not valid.
At line:1 char:32
+ while($true) { $c = Get-Counter <<<< -ComputerName c (c:
\....unters_en_meas
ured.ps1 _lm_w3svc_1_root_vc); sleep -sec 5 }
+ CategoryInfo : InvalidResult: (:) [Get-Counter],
Exception
+ FullyQualifiedErrorId :
CounterPathIsInvalid,Microsoft.PowerShell.Commands.GetCounterCommand
There is one error for each counter related to .NET memory. Any ideas?
One bonus question - assume counters for some process work ok (e.g. I
measure processor activity). Then I close the process so some errors
are raised (it's ok). Then I start the process again, but I'm not able
to run the counters again, because it is somehow cached that the
process doesn't exist (I get something like path is invalid again).
How can I presuade PowerShell that the counters are valid now?