param( [string]$JsonOut = $null ) # Initialize script resolution $script:resolution = "Unknown" $script:primaryGPU = $null Write-Host "Retrieving GPU information using Get-CimInstance..." try { $gpus = Get-CimInstance Win32_VideoController -ErrorAction Stop } catch { Write-Error "Failed to retrieve GPU info: $_" return } function Get-GPUType { param($gpuName) $n = $gpuName.ToLower() if ($n -match 'meta|virtual|mirage|basic display|remote|vmware|virtualbox|citrix|qxl|parallels|sunshine|parsec') { return "Virtual / Software GPU" } elseif ($n -match 'intel|uhd|iris|hd graphics') { return "Integrated GPU" } elseif ($n -match 'nvidia|geforce|quadro|tesla|rtx|gtx|amd|radeon|rx') { return "Discrete GPU" } return "Unknown GPU Type" } # Hold categorized GPUs $discreteGPUs = @() $integratedGPUs = @() $virtualGPUs = @() $allGPUs = @() foreach ($gpu in $gpus) { $name = if ($gpu.Name) { $gpu.Name } else { "Unknown GPU" } $gpuType = Get-GPUType $name $videoProcessor = if ($gpu.VideoProcessor) { $gpu.VideoProcessor } else { "Unknown Processor" } $driverVersion = if ($gpu.DriverVersion) { $gpu.DriverVersion } else { "Unknown Driver Version" } # RAM $adapterRAMGB = if ($gpu.AdapterRAM -and $gpu.AdapterRAM -gt 0) { [math]::Round($gpu.AdapterRAM / 1GB, 2) } else { 0 } # Resolution logic if ($gpu.CurrentHorizontalResolution -and $gpu.CurrentVerticalResolution) { $res = "{0}x{1}" -f $gpu.CurrentHorizontalResolution, $gpu.CurrentVerticalResolution } elseif ($gpu.VideoModeDescription -match '(\d+)\s*x\s*(\d+)') { $res = "{0}x{1}" -f $Matches[1], $Matches[2] } else { $res = "Unknown" } $gpuInfo = [pscustomobject]@{ Name = $name Type = $gpuType RAMGB = $adapterRAMGB Resolution = $res DriverVersion = $driverVersion VideoProcessor = $videoProcessor } $allGPUs += $gpuInfo switch ($gpuType) { "Discrete GPU" { $discreteGPUs += $gpuInfo } "Integrated GPU" { $integratedGPUs += $gpuInfo } "Virtual / Software GPU" { $virtualGPUs += $gpuInfo } default { $virtualGPUs += $gpuInfo } } # Print only hardware GPUs if ($gpuType -ne "Virtual / Software GPU") { Write-Host "`n--- GPU Information ---" Write-Host "GPU Name: $name" Write-Host "GPU Type: $gpuType" Write-Host "Video Processor: $videoProcessor" Write-Host "Adapter RAM: $adapterRAMGB GB" Write-Host "Driver Version: $driverVersion" Write-Host "Detected Res: $res" Write-Host "-----------------------" } } # Determine primary GPU by preference order foreach ($list in @($discreteGPUs, $integratedGPUs, $virtualGPUs)) { foreach ($gpu in $list) { if ($gpu.Resolution -and $gpu.Resolution -ne "Unknown") { $script:primaryGPU = $gpu $script:resolution = $gpu.Resolution break } } if ($script:primaryGPU) { break } } # CPU Name $cpu = "Unknown" try { $cpuObj = Get-CimInstance Win32_Processor | Select-Object -First 1 if ($cpuObj -and $cpuObj.Name) { $cpu = $cpuObj.Name.Trim() } } catch {} # RAM $ram = "Unknown" try { $ramObj = Get-CimInstance Win32_ComputerSystem if ($ramObj -and $ramObj.TotalPhysicalMemory) { $ram = [math]::Round($ramObj.TotalPhysicalMemory / 1GB, 0) } } catch {} Write-Host "`n--- Detected System ---" Write-Host "CPU: $cpu" Write-Host "RAM: $ram GB" Write-Host "Primary GPU: $($script:primaryGPU.Name)" Write-Host "Display Resolution: $script:resolution" Write-Host "-----------------------" # Optional JSON Export if ($JsonOut) { $output = [pscustomobject]@{ CPU = $cpu RAM_GB = $ram PrimaryGPU = $script:primaryGPU Resolution = $script:resolution AllGPUs = $allGPUs } $output | ConvertTo-Json -Depth 6 | Out-File -Encoding UTF8 $JsonOut Write-Host "Exported system info to: $JsonOut" }