Jakub Zahorak
Jakub Zahorak

Reputation: 33

Multiple monitors/graphic cards info using powershell

I am using the following script to get system information. The script works fine, I have problem when computers with two graphic cards or multiple monitors. For more monitors I found this Get Screen resolution using WMI/powershell in Windows 7 but don't know how to format/implement it to fit my script.

$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

I basically want to get file with information in lines, with GPU separated with comma and detection for multiple screens and if there are multiple monitors printed their respective resolutions.

Upvotes: 1

Views: 5445

Answers (1)

user6811411
user6811411

Reputation:

I suggest changing the line $GPU = to

$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("; ")

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

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

Upvotes: 1

Related Questions