1

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.

Community
  • 1
  • 1
Jakub Zahorak
  • 33
  • 1
  • 7

1 Answers1

1

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
  • Thanks a lot. What about resolution of said monitors? "Resolution: " + $RES.CurrentHorizontalResolution + "x" + $RES.CurrentVerticalResolution >> $EXTXT will get something like: Resolution: 1920 1920 x 1080 1080 – Jakub Zahorak Jan 18 '17 at 18:39
  • @JakubZahorak Changed the above script. –  Jan 18 '17 at 18:44
  • On laptop (2xGPU, 2xmonitor): Monitor: Default Monitor 1366x768; Dell P2414H(Analog) 1920x1080 On desktop (1xGPU, 1xmonitor) Monitor: SyncMaster XL2370(Digital) x `-Get-WmiObject -Class Win32_DesktopMonitor` will also result in empty Width and Height :/ `-Get-WmiObject -Class Win32_VideoController` will fetch Width and Height, (with one monitor) but only resolution of main monitor on laptop – Jakub Zahorak Jan 18 '17 at 19:41
  • I do get also inconsistent results on the dual monitor pcs I tested. [this link](https://community.spiceworks.com/topic/707515-monitor-inventory) provides some monitor info not presented by the above cmdlets/methods, but not the resolution :-\ –  Jan 18 '17 at 20:01
  • 1
    `[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.Screens") $Screens = ([system.windows.forms.screen]::AllScreens | ForEach-Object {"$($_.Bounds.width)x$($_.Bounds.Height)"}) -join("; ")` and `"Resolution: " + $Screens >> $EXTXT` Did the trick in the end. Thanks @LotPings for help – Jakub Zahorak Jan 18 '17 at 21:24
  • @JakubZahorak Ty, I inserted your code to present a complete answer. –  Jan 18 '17 at 22:31