为什么在Windows 10上的PowerShell中无法获得屏幕分辨率?

时间:2018-07-21 07:46:11

标签: powershell wmi

我在Get Screen resolution using WMI/powershell in Windows 7中键入命令,但结果为空(我在Surface Pro 2017上,单屏显示)?

enter image description here

1 个答案:

答案 0 :(得分:3)

我没有Surface,但这行得通吗?

Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.Screen]::PrimaryScreen
[pscustomobject]@{
    DeviceName   = $screen.DeviceName.Split('\\')[-1]
    Width        = $screen.Bounds.Width
    Height       = $screen.Bounds.Height
    BitsPerPixel = $screen.BitsPerPixel
}

编辑

使用CIM_VideoController

$screen = Get-CimInstance -ClassName CIM_VideoController
[pscustomobject]@{
    DeviceName   = $screen.Caption
    Width        = $screen.CurrentHorizontalResolution
    Height       = $screen.CurrentVerticalResolution
    BitsPerPixel = $screen.CurrentBitsPerPixel
}