title: Performance Counter API call error in Powershell
body: <p>I want to get specific informations about performance from Perfmon via Powershell and write it to a .csv file, using a script ran by another service. I know Powershell can give some interesting error message, thus I want to hear if any of you could discipher what exactly I'm doing wrong.</p>
  
  <p>The code I'm trying to make work seems like this:</p>
  
  <pre><code>$date = (Get-Date).ToShortDateString()
  Get-Counter
      $gc = @("\Memory\% Committed Bytes In Use",
              "\Memory\Available MBytes",
              "\Network Interface(*)\Current Bandwith",
              "\Network Interface(*)\Packets Recieved/sec",
              "\Network Interface(*)\Packets Sent/sec",
              "PhysicalDisk(_Total)\Disk Write Bytes/sec",
              "PhysicalDisk(_Total)\Disk Read Bytes/sec",
              "Processor(_Total)\% Processor Time",
              "Processor(_Total)\% Idle Time")
  Get-Counter -counter $gc -SampleInterval 2 -MaxSamples 8 | export-counter -path C:\PerfMon2-$date.csv -FileFormat csv
  </code></pre>
  
  <p>with an error like this:</p>
  
  <pre><code>Get-Counter : Internal performance counter API call failed. Error: c0000bb9.
  At C:\Users\jenstmar\Desktop\Nuværende Projekter\Perfmon.ps1:13 char:12
  + Get-Counter &lt;&lt;&lt;&lt;  -counter $gc -SampleInterval 2 -MaxSamples 1 | export-counter -path C:\PerfMon2-$date.csv -FileFormat cs
  v
      + CategoryInfo          : InvalidResult: (:) [Get-Counter], Exception
      + FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand
  </code></pre>
  
  <p>Yet, if I choose performance counter categories instead of specifics, it works. An example would be this:</p>
  
  <pre><code>$date = (Get-Date).ToShortDateString()
      Get-counter 
          $gc = (Get-Counter -listset "Network Interface").paths 
          $gc += (Get-Counter -listset "Processor").paths 
          $gc += (Get-Counter -ListSet "Processor Information").paths
          $gc += (Get-Counter -listSet "memory").paths
          $gc += (Get-Counter -listSet "PhysicalDisk").paths
      get-counter -counter $gc -SampleInterval 2 -MaxSamples 8 | export-counter -path C:\PerfMon-$date.csv -FileFormat csv
  </code></pre>