问题描述
我的问题是,如何删除变量中的某些内容?我只想获取屏幕的坐标。
所以我可以使用$screen1 = Get-WmiObject win32_desktopmonitor
来获取内容,但是我不知道该如何摆脱我不需要的其余内容。
以下是输出:
deviceid : DesktopMonitor1
displayType :
MonitorManufacturer :
Name : Standardmonitor
ScreenHeight :
ScreenWidth :
deviceid : DesktopMonitor2
displayType :
MonitorManufacturer :
Name : Standardmonitor
ScreenHeight : 1200
ScreenWidth : 1920
deviceid : DesktopMonitor3
displayType :
MonitorManufacturer : (Standardmonitortypen)
Name : PnP-Monitor (Standard)
ScreenHeight : 1200
ScreenWidth : 1920
我只需要DesktopMonitor2的屏幕高度和宽度,而另一个我要保存在新变量中。
我需要它以信息亭模式在不同屏幕上打开两个浏览器屏幕。有人可以帮我吗?
解决方法
我没有注意到您使用的是旧版Windows PowerShell。
((我建议您将Windows PowersShell 5.1或更高版本更新为最新版本:使用PowerShell Core Get-CimInstance
)
无论如何,对于PowerShell 3.0,您应该能够做到这一点:
$Screens = Get-WmiObject win32_desktopmonitor
$Screen2 = $Screens | Where-Object { $_.DeviceID -eq DesktopMonitor2 }
$Width2 = $Screen2.ScreenWidth
$Height2 = $Screen2.ScreenHeight