title: WMI Scripting Windows 8 error
body: <p>I have a problem with WMI in a machine with a Windows 8 Home Edition. I need to catch the CPU usage and the ProcessID by process. I've tried so many ways:</p>
  
  <ul>
  <li>ShellExecute in Delphi</li>
  <li>A *.bat with the code</li>
  <li>A *.vbs</li>
  <li>A *.vbs executed by a *.bat</li>
  <li>A *.ps1</li>
  <li>A *.ps1 executed by a *.bat</li>
  </ul>
  
  <p>(Maybe some of these ways can be really stupid, but I've tried anyway)</p>
  
  <p>In the User-Click it works perfectally, but by a standalone applicantion it doesn't work.
  I have opened the Security on WMIMGMT.msi of some folders and the execution policy (in PowerShell) now is UNRESTRICTED.</p>
  
  <p>This is the code on the *.ps1 file:</p>
  
  <pre><code>$ErrorActionPreference = "SilentlyContinue"
  Stop-Transcript | Out-Null
  $ErrorActionPreference = "Continue"
  $perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
  foreach ($p in $peflist) {
    "" + $p.IDProcess + ";" + $p.PercentProcessTime
  }
  </code></pre>
  
  <p>This is the code on *.bat</p>
  
  <pre><code>powershell -ExcetutionPolicy Unrestricted -File "C:\Somefolder\PP.ps1" &gt; C:\SomeFolder\output.txt
  </code></pre>
  
  <p>All I got is this output:</p>
  
  <pre>get-wmiobject : Invalid query "select * from Win32_Win32_PerfFormattedData_PerfProc_Process"
  In C:\Somefolder\PP.ps1:4 character: 14
  + $perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
  +          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       + CategoryInfo         : InvalidArgument: (:) [Get-WmiObject], ManagementException
       + FullyQualifiedErroID : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand</pre>
  
  <hr>
  
  <p><strong>Edit1:</strong> The code copied as asked:</p>
  
  <ul>
  <li><p>*.ps1:</p>
  
  <pre><code>$ErrorActionPreference="SilentlyContinue" 
  Stop-Transcript | out-null 
  $ErrorActionPreference = "Continue"
  $perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process) 
  foreach ($p in $perflist) {
    "" + $p.IDProcess + ";" + $p.PercentProcessorTime
  } 
  </code></pre></li>
  <li><p>*.bat</p>
  
  <pre><code>powershell -executionPolicy unrestricted -file "C:\MonitorPerformance\test.ps1" &gt; C:\MonitorPerformance\output1.txt
  </code></pre></li>
  <li><p>Output: (Consulta inválida = Invalid Query; No = in; caractere = character)</p>
  
  <pre class="lang-none prettyprint-override"><code>get-wmiobject : Consulta inv lida "select * from Win32_PerfFormattedData_PerfProc_Process"
  No C:\MonitorPerformance\test.ps1:4 caractere:14
  + $perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
  +              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ManagementException
      + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
  </code></pre></li>
  </ul>