title: Output values from multiple counters in Powershell
body: <p>I have the following bit of code that I have borrowed, but I am not getting the output I expected. Eventually I want to create a list/array for each counter containing the last x number of values. 
  But I expected that the <code>$obj</code> would be a list of counters that I could step though and the code below would give an output that would have <code>***</code> between each counter collected, but this is not the case? </p>
  
  <p>How can I loop though each counter in turn and get its value? </p>
  
  <pre><code>$counters = get-counter -ComputerName sql -Counter "\SQLServer:General Statistics\User Connections","\SQLServer:Memory Manager\Memory Grants Pending","\SQLServer:SQL Statistics\batch requests/sec","\SQLServer:SQL Statistics\sql compilations/sec","\SQLServer:SQL Statistics\sql re-compilations/sec" -SampleInterval 1
  
  foreach($metric in $counters)            
  {            
    $obj = $metric.CounterSamples | Select-Object -Property Path, CookedValue;            
  
    write-host $obj 
    write-host "***"
  }  
  </code></pre>
  
  <p>The current output I get is below: </p>
  
  <pre><code>@{Path=\\sql\\sqlserver:general statistics\user connections; CookedValue=96} @{Path=\\sql\\sqlserver:memory manager\memory grants pending; CookedValue=0} @{Path=\\sql\\sqlserver:sql statistics\batch requests/sec; CookedValue=110.969626692457} @{Path=\\sql\\sqlserver:sql statistics\sql compilations/sec; CookedValue=17.9950745987768} @{Path=\\sql\\sqlserver:sql statistics\sql re-compilations/sec; CookedValue=5.99835819959228}
  ***
  </code></pre>
  
  <p>I was hoping for more like this: </p>
  
  <pre><code>Counters 1 = 0.5
  ***
  Counter 2 = 1.2
  *** 
  </code></pre>
  
  <p>This would break the output into the separate counters, but I think I understand the comments now. </p>