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
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityWindows 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.
Get-Counter
. Although Get-Counter
run few second.
Get-WmiObject Win32_VideoController
?