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.
[PS] C:\>Get-Counter -Counter "\LogicalDisk(_Total)\% Free Space"
The result is given:
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:
$($(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?