【问题标题】:Exporting Windows Resource Monitor Data with Powershell使用 Powershell 导出 Windows 资源监视器数据
【发布时间】:2017-04-03 20:17:29
【问题描述】:

问题定义:我们已经在我们的 Web 服务器中进行了一些配置级别的更改,该服务器基本上是一个 IIS 服务器。我们将线程数从默认的 300 增加到了大约 450。

而且这些更改可能会使我们的服务器崩溃。

所以我们想监控工作线程,并定期将其记录到数据库中。

我目前的进展:

到目前为止,我能够通过下面提到的 Powershell 命令运行一个 exe 来获取详细信息。

(只需将 w3wp.exe 替换为任何进程名称即可获得结果)

$name = "w3wp.exe" 
$processHandle = (Get-CimInstance Win32_Process -Filter "Name = '$name'").ProcessId
$Threads = Get-CimInstance -Class Win32_Thread -Filter "ProcessHandle = $processHandle"
$threads | Select-Object priority, thread*, User*Time, kernel*Time |
Out-GridView -Title "The $name process has $($threads.count) threads"

问题:在上面提到的 PowerShell 脚本中,当 w3wp.exe 使用多个 PID 运行时,它无法为我提供 exe 的结果。

有没有办法让我们获得多个运行的 exe 的结果?

表格应该是

处理器名称| PID|工人姓名|线程数|

【问题讨论】:

    标签: windows powershell


    【解决方案1】:

    所以,我在运行你的代码时遇到了一个错误,我希望你也会得到这个错误

     Get-CimInstance : Invalid query 
     At line:3 char:12
     + $Threads = Get-CimInstance -Class Win32_Thread -Filter "ProcessHandle ...
     +            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         + CategoryInfo          : InvalidArgument: (:) [Get-CimInstance], CimException
         + FullyQualifiedErrorId : HRESULT 0x80041017,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
    

    这是有道理的,因为 -Filter 看起来像这样......就像我使用 chrome.exe 作为测试一样。这是无效的。

    ProcessHandle = 7224 7420 8688 8800 8916 460 10884 7340 10956 6756 14604 13260 9588 18020 22264 11516 17684 12664
    

    所以我只是添加了一个循环以允许多个$processHandles,它似乎工作正常。

    $Threads = $processHandle | Foreach-Object{
        Get-CimInstance -Class Win32_Thread -Filter "ProcessHandle = $_"
    }
    

    【讨论】:

      猜你喜欢
      • 2012-01-05
      • 2011-07-29
      • 2021-12-24
      • 1970-01-01
      • 2023-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多