Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to count number of screens via powershell or cmd

I wanted to count the number of screens detected via powershell/cmd.

got the below to work but I wanted to count the number of screens detected as numeric.

@for /F "usebackq tokens=2 delims=: " %i IN (`powershell.exe Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams ^| findstr /r /C:"Active"`) do @echo %i 

this returns the below suppose I have 2 screens connected. Would anyone help me change the output to the number of screens active instead which is true to numeric/or count the number of true? i.e = 2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

True 
True

>Solution :

You already have the solution, you’re just mixing a batch syntax with PowerShell for no reason.

@(Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams).Length is a pure PowerShell solution.

If you want to filter it to only active displays, then @(Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams | where-object { $_.Active }).Length.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading