As we all know we can do Get-Counter and than provide the path to the counter, e.g., Get-Counter "\\Processor(_Total)\% Processor Time")
So now I want to do the same thing only then with a variable as path:
$myPath = "[THIS IS MY PATH]"
$metricValue = [int] ((Get-Counter $myPath).countersamples | select -property
cookedvalue).cookedvalue
Unfortunately I get the following error:
Get-Counter : The called instance is not available At [Path] +
$metricValue = [int] ((Get-Counter <<<< -Counter $myPath).countersamples |
select -property cookedvalue).cookedvalue
+ CategoryInfo : InvalidResult: (:) [Get-Counter], Exception
+ FullyQualifiedErrorId :
CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand
So I cannot put a variable after Get-Counter for the path, but I need to do that!
Is there a solution to do so?