Sometime ago now I was given the challenge to get the value out of a get-counter in a Powershell, I thought the answer snippet should be posted for future reference.
The following Powershell command gives a value buried with result information.
1 |
[PS] C:\>Get-Counter -Counter "\LogicalDisk(_Total)\% Free Space" |
The result is given:
1 2 3 |
Timestamp CounterSamples --------- -------------- 12/04/2012 11:19:57 AM \\workstation1\logicaldisk(_total)\% free space : 66.8695878637932 |
To get the true value to be used in other powershell code we need to find the cooked value.
The following line returns just the value:
1 |
$($(Get-Counter -Counter "\LogicalDisk(_Total)\% Free Space").countersamples).cookedvalue |
Which just returns the value only: 66.8695878637932
I hope this will be useful to others?
Very usefull !
Great Thanks ! 🙂
Jean
I thank you. My remaining hair thanks you, too.