Remote Processor / Memory usage of Specific Process

I'm doing a project to grab the CPU usage %, as well as RAM usage (in KB) for specific processes, about 6.

I came across a great guide for getting cpu%, which uses this code:

# Option A: This is if you just have the name of the process; partial name OK
$ProcessName = "winlogon"

# Option B: This is for if you just have the PID; it will get the name for you
#$ProcessPID = "6860"

#$ProcessName = (Get-Process -Id $ProcessPID).Name

$CpuCores = (Get-WmiObject Win32_ComputerSystem).NumberOfLogicalProcessors
$Samples = (Get-Counter "Process($Processname*)% Processor Time").CounterSamples
$Samples | Select InstanceName,
    @{Name="CPU %";Expression={[Decimal]::Round(($_.CookedValue / $CpuCores), 2)}}

However, I cannot find a way to get it to hit remote machines as well. I can use this to list local processes, and I've tried adding the -ComputerName switch with a PC Name to the Get-WmiObject to grab the remote processor count. This causes the script to fail at Select . I've also tried hard-coding the $CpuCores value with 2 and using Get-Counter against a remote machine, but I'm not sure how to format it given the specific example.

I have no issue writing this from scratch, but I'm having a rough time figuring out how to get either the CPU or RAM usage of specific processes. The end goal is to display the results in a TextBox control that would be readable by Name, CPU % utilization, and memory utilization.

I have the GUI that takes a PC name, and a textbox for the results, I'm having trouble developing the logic to even get the data I need. Any thoughts? I've spent about 2 days combing the Internet and found many methods for both CPU and memory usage, but nothing that I can stick together, or use remotely. I'm not new to PowerShell, but this has been perplexing. Any help in developing the logic would be appreciated.

链接地址: http://www.djcxy.com/p/79826.html

上一篇: 以编程方式检索进程的峰值虚拟内存

下一篇: 特定进程的远程处理器/内存使用情况