Help with Bat Script for Displaying Monitor Info

0
0
Asked By TechNinja42 On

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!

3 Answers

Answered By GadgetGuru88 On

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!

MonitorMaverick -

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

Answered By CodeMaster99 On

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!

HelpfulHacker007 -

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

Answered By BatchBot On

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!

NewbieCoder -

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.
```

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.