简体   繁体   中英

Powershell: How can i get the primary screen resolution of a logged in user?

Our current scenario is this:

We have more than 80 tablet computers (running Windows 10) in our network that run under the same user ( DefaultUser ). In order to verify that the display settings are correctly set, we would like to use a powershell script to automatically check the used resolution remotely with a support user account.

So far, we know how to get the primary screen resolution for the user under which the script gets executed (which is rather easy):

  // get primary screen width
  Add-Type -AssemblyName System.Windows.Forms
  [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width   // height accordingly

In case we execute this script on one of the tablets using the support account, we get the primary screen resolution for the support account user - but not for the desired user DefaultUser .

How can we get the resolution for the DefaultUser ?

The only solution that easily comes to my mind is a rather ugly thing: Using the windows task scheduler i could create a task that executes the script (under the defaultUser) to get the screen resolution and write the result(s) into a file that can be accessed by the support user account. But i am looking for something more elegant.

You may be able to use CIM or WMI to get from point a to b.

CIM_VideoController is the class that would contain the resolution.

Using PowerShell Core:

Get-CimInstance CIM_VideoController | Select SystemName, CurrentHorizontalResolution, CurrentVerticalResolution

Using Windows PowerShell:

Get-WmiObject Win32_VideoController | Select SystemName, CurrentHorizontalResolution, CurrentVerticalResolution

You should be able to open the proper ports to use either of these options remotely (though you could also probably get away with using Invoke-Command to run them, as long as you use CredSSP or Kerberos Delegation to take the 2nd hop problem into account).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM