7

I have tried Get-Process and Get-CimInstance Win32_Process to get GPU usage and GPU memory, but both of them can't offer those information.

In Windows Task Manager, it can show GPU memory.

So, is there a way to get those in powershell

5
  • Have you tried anything around Get-WmiObject Win32_VideoController? Mar 12, 2021 at 8:28
  • Yes, I have tried too.But it doesn't help
    – bin381
    Mar 12, 2021 at 8:33
  • @Lee_Dailey - PowerShell 7.1 is literally the next version and is nearly a full replacement for PowerShell 5.1; 5.1 isn’t being developed and 7.1 should be used instead
    – Ramhound
    Mar 12, 2021 at 16:56
  • @Ramhound - what you just said is what i said. [grin] yes it is the NEXT version ... but it aint technically an UPGRADE ... at least not yet. for windows, the ONLY version that is fully supported is ps5.1 ... ps7 is a side-grade that lacks full compatibility. ps7 otta be when it offers something useful that ps5.1 does not. the web cmdlets are prime examples of why one would use ps7 instead of ps5.1 at this time
    – Lee_Dailey
    Mar 12, 2021 at 17:22
  • PS 7.1 is nearly a full replacement for 5.1
    – Ramhound
    Mar 12, 2021 at 18:43

1 Answer 1

7

Windows uses Performance Counters to track this type of thing. You can get the values in powershell via Get-Counter. Depending on your GPU and drivers, you may have more specific counters available, but these examples should always be available:

# Example to get GPU usage counters for a specific process:
$p = Get-Process dwm
((Get-Counter "\GPU Process Memory(pid_$($p.id)*)\Local Usage").CounterSamples | where CookedValue).CookedValue | 
    foreach {Write-Output "Process $($P.Name) GPU Process Memory $([math]::Round($_/1MB,2)) MB"}
((Get-Counter "\GPU Engine(pid_$($p.id)*engtype_3D)\Utilization Percentage").CounterSamples | where CookedValue).CookedValue |
    foreach {Write-Output "Process $($P.Name) GPU Engine Usage $([math]::Round($_,2))%"}

# Outputs:
Process dwm GPU Process Memory 259.36 MB
Process dwm GPU Engine Usage 0.47%


# Example to get total GPU usage counters:
$GpuMemTotal = (((Get-Counter "\GPU Process Memory(*)\Local Usage").CounterSamples | where CookedValue).CookedValue | measure -sum).sum
    Write-Output "Total GPU Process Memory Local Usage: $([math]::Round($GpuMemTotal/1MB,2)) MB"
$GpuUseTotal = (((Get-Counter "\GPU Engine(*engtype_3D)\Utilization Percentage").CounterSamples | where CookedValue).CookedValue | measure -sum).sum
    Write-Output "Total GPU Engine Usage: $([math]::Round($GpuUseTotal,2))%"

# Outputs:
Total GPU Process Memory Local Usage: 511.36 MB
Total GPU Engine Usage: 0.77%

I found these counter names by running Get-Counter -ListSet 'GPU*', and taking the Counter values from there. It looks like GPU engine usage is broken down into 4 types:

engtype_3D
engtype_VideoDecode
engtype_Copy
engtype_VideoProcessing

I'm just summing engtype_3D in the example, since it is the only one with usage on my system. These values all match up with what displays in windows Task Manager, so it should be accurate enough.

1
  • Thanks!! I do can get GPU memory usage from Get-Counter. Although Get-Counter run few second.
    – bin381
    Mar 15, 2021 at 14:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .