使用 powershell 的多个 monitors/graphic 卡信息

Multiple monitors/graphic cards info using powershell

我正在使用以下脚本来获取系统信息。该脚本工作正常,当计算机有两个图形卡或多个显示器时,我遇到了问题。 对于更多显示器,我发现了这个 Get Screen resolution using WMI/powershell in Windows 7 但不知道如何 format/implement 它适合我的脚本。

$user = [Environment]::UserName
$System = Get-CimInstance CIM_ComputerSystem
$BIOS = Get-CimInstance CIM_BIOSElement
$OS = Get-CimInstance CIM_OperatingSystem
$CPU = Get-CimInstance CIM_Processor
$osup = Get-WmiObject win32_operatingsystem
$uptime = (Get-Date) - ($osup.ConvertToDateTime($osup.lastbootuptime))
$GPU = Get-CimInstance CIM_VideoController
$RES = Get-WmiObject Win32_VideoController
$used = ($System.TotalPhysicalMemory/1MB)-($OS.FreePhysicalMemory/1KB)

$EXTXT = "$env:USERPROFILE\Desktop\vq.txt"

Clear-Host

$user + "@" + $system.Name >> $EXTXT
"OS: " + $OS.caption + " " + $osup.OSArchitecture >> $EXTXT
"Model: " + $System.Model >> $EXTXT
"Kernel: " + $OS.Version >> $EXTXT
"Uptime: " + $Uptime.Days + "d " + $Uptime.Hours + "h " + $Uptime.Minutes + "m " >> $EXTXT
"Resolution: " + $RES.CurrentHorizontalResolution + "x" + $RES.CurrentVerticalResolution >> $EXTXT
"CPU: " + $CPU.Name >> $EXTXT
"GPU: " + $GPU.Name >> $EXTXT
"Memory: " + "{0:N0}" -f $used + "MB" + " / " + "{0:N0}" -f ($System.TotalPhysicalMemory/1MB) + "MB" >> $EXTXT

我基本上想要获取包含行信息的文件,GPU 以逗号分隔并检测多个屏幕,如果有多个显示器打印它们各自的分辨率。

我建议将行 $GPU = 更改为

$GPU=(Get-CimInstance CIM_VideoController|%{$_.Name}) -join("; ")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.Screens") 
$Screens = ([system.windows.forms.screen]::AllScreens | %{"$($_.Bounds.width)x$($_.Bounds.Height)"}) -join("; ")

"GPU: " + $GPU.Name >> $EXTXT

"GPU: " + $GPU >> $EXTXT
"Resolution: " + $Screens