【问题标题】:Cannot find the process identifier on remote computer using Powershell使用 Powershell 在远程计算机上找不到进程标识符
【发布时间】:2016-11-01 17:15:41
【问题描述】:

我正在尝试使用以下代码获取 CPU 使用率最高的进程以及运行它们的用户:

$ProcessList = gwmi Win32_PerfFormattedData_PerfProc_Process -ComputerName $ComputerName -Credential $cred | select IDProcess,Name,PercentProcessorTime | where { $_.Name -ne "_Total" -and $_.Name -ne "Idle"} | sort PercentProcessorTime -Descending | select -First 3
$TopProcess = @()
ForEach ($Process in $ProcessList) {
  $row = new-object PSObject -Property @{
    Id = $Process.IDProcess
    Name = $Process.Name
    User = (gwmi Win32_Process -ComputerName $ComputerName -Credential $cred | where {$_.ProcessId -eq $Process.IDProcess}).GetOwner().User
    CPU = $Process.PercentProcessorTime
    Description = (Get-Process -Id $Process.IDProcess).Description
  }
  $TopProcess += $row
}

但是得到

Get-Process : 找不到进程标识符为 20060 的进程。 在 C:\Users\Jasons1\CPUUsage.ps1:13 char:20 + 描述 = (Get-Process -Id $Process.IDProcess).Description + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (20060:Int32) [Get-Process], ProcessCommandException + FullyQualifiedErrorId : NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand

第一次。

【问题讨论】:

    标签: powershell


    【解决方案1】:
      Description = (Get-Process -Id $Process.IDProcess).Description
    

    通过

      Description = (gwmi Win32_Process -ComputerName $ComputerName -Credential $cred | where {$_.ProcessId -eq $Process.IDProcess}).Description 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-26
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-21
      相关资源
      最近更新 更多