Help with Bat Script for Displaying Monitor Info

May 2, 2025 3 answers
Asked by pwm.25pct
I'm trying to create a batch script that pulls useful hardware details about my monitors. While I can correctly display the names and count of my monitors, the resolution and refresh rates are coming up wrong. I've tried using PowerShell commands, but I'm hitting a wall with the monitor details. Here's the script I'm working with: ```batch echo Monitor Information: powershell -Command "$monitors = Get-CimInstance -Class Win32_PnPEntity | Where-Object { $_.PNPClass -eq 'Monitor' }; $displaySettings = Get-CimInstance -Class Win32_VideoController | Select-Object DeviceID, CurrentHorizontalResolution, CurrentVerticalResolution, CurrentRefreshRate; foreach ($monitor in $monitors) { $monitorName = $monitor.Name; $displayInfo = $displaySettings | Where-Object { $_.DeviceID -match 'VideoController' }; Write-Output ('Monitor: ' + $monitorName); if ($displayInfo) { Write-Output ('Resolution: ' + $displayInfo.CurrentHorizontalResolution + ' x ' + $displayInfo.CurrentVerticalResolution + ' @ ' + $displayInfo.CurrentRefreshRate + ' Hz') } else { Write-Output 'Resolution: Not available' }; Write-Output '----------------------' }" echo. ``` Currently, I'm seeing a consistent output for every monitor: - Monitor: Generic Monitor (DELL AW2518HF) - Resolution: 1920 x 1080 @ 60 Hz I used to rely on Wmic for this info, but it seems to be phased out. After a lot of frustration, I'm reaching out to see if anyone has advice or a better way to gather this data accurately. Thanks!

Answers

2stepWaltz
If you have old Wmic code that worked before, it might be useful to look into it again! Also, try running your script in a `.ps1` file instead of directly in the command line. It makes debugging way easier! Plus, reformat your existing script into a file, so you donโ€™t have to scroll through mile-long commands. That might clarify things a lot!

ceramic.teapot: Thanks for the tip! I'm still learning, but Iโ€™ll give that a shot. Hereโ€™s my old Wmic command that worked until recently: ```batch echo Monitor Information: powershell -Command "Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID | ForEach-Object { [PSCustomObject]@{ MonitorName = ([System.Text.Encoding]::ASCII.GetString($_.UserFriendlyName) -replace '\0', '') } } | Format-Table -AutoSize" echo. ```

Reply to this answer
0 degrees Celsius
You might want to check out the new PowerShell features since Wmic is being phased out. There's a good article on the Microsoft Tech Community about alternatives that could help. The new PowerShell WMI is designed to replace what you had with Wmic, so give that a look!

sidewalk_chalk: Yeah, but keep in mind that the command structure is pretty similar, so it shouldn't be too complicated to switch over.

Reply to this answer
have another look
I had a similar issue with `Win32_VideoController`. It usually only gives one instance if you have a single GPU, which makes it hard to connect to multiple displays. If you're open to third-party tools, I recommend using the `DisplayConfig` module. It provides much more detailed information about monitors. A quick install with `Install-Module DisplayConfig` and then you can utilize `Get-DisplayInfo`. Definitely worth trying!

~9th vote: Exactly! I'm diving into that too, hoping it gives me a standardized way to pull this info without admin access.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions