Skip to content

Latest commit

 

History

History
70 lines (61 loc) · 1.79 KB

File metadata and controls

70 lines (61 loc) · 1.79 KB

The 'check-gpu.ps1' Script

check-gpu.ps1

Parameters

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

Script Content

<#
.SYNOPSIS
	Checks the GPU status
.DESCRIPTION
	This PowerShell script queries the GPU status and prints it.
.EXAMPLE
	PS> ./check-gpu.ps1
	✅ NVIDIA Quadro P400 GPU (2GB RAM, 3840x2160 pixels, 32-bit, 59Hz, driver 31.0.15.1740) - status OK
.LINK
	https://github.com/fleschutz/PowerShell
.NOTES
	Author: Markus Fleschutz, Tyler MacInnis | License: CC0
#>

function Bytes2String { param([int64]$Bytes)
	if ($Bytes -lt 1000) { return "$Bytes bytes" }
	$Bytes /= 1000
	if ($Bytes -lt 1000) { return "$($Bytes)KB" }
	$Bytes /= 1000
	if ($Bytes -lt 1000) { return "$($Bytes)MB" }
	$Bytes /= 1000
	if ($Bytes -lt 1000) { return "$($Bytes)GB" }
	$Bytes /= 1000
	return "$($Bytes)TB"
}

try {
	if ($IsLinux) {
		# TODO
	} else {
		$Details = Get-WmiObject Win32_VideoController
		foreach ($GPU in $Details) {
			$Model = $GPU.Caption
			$RAMSize = $GPU.AdapterRAM
			$ResWidth = $GPU.CurrentHorizontalResolution
			$ResHeight = $GPU.CurrentVerticalResolution
			$BitsPerPixel = $GPU.CurrentBitsPerPixel
			$RefreshRate = $GPU.CurrentRefreshRate
			$DriverVersion = $GPU.DriverVersion
			$Status = $GPU.Status
			Write-Host "$Model GPU ($(Bytes2String $RAMSize) RAM, $($ResWidth)x$($ResHeight) pixels, $($BitsPerPixel)-bit, $($RefreshRate)Hz, driver $DriverVersion) - status $Status"
		}
	}
	exit 0 # success
} catch {
	"⚠️ ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

(page generated by convert-ps2md.ps1 as of 12/27/2025 11:08:53)