使用powershell

时间:2017-01-18 15:28:44

标签: powershell wmi

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

$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用逗号隔开并检测多个屏幕,如果有多个显示器打印各自的分辨率。

1 个答案:

答案 0 :(得分:1)

我建议将行$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