从Powershell中的变量中删除内容

从Powershell中的变量中删除内容,powershell,powershell-3.0,Powershell,Powershell 3.0,我的问题是,如何从变量中删除一些内容?我只想得到屏幕的坐标 因此,我可以使用$screen1=get WmiObject win32\u desktopmonitor获取内容,但我不知道如何删除其余我不需要的内容 以下是输出: DeviceID : DesktopMonitor1 DisplayType : MonitorManufacturer : Name : Standardmonitor ScreenHeight

我的问题是,如何从变量中删除一些内容?我只想得到屏幕的坐标

因此,我可以使用
$screen1=get WmiObject win32\u 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的屏幕高度和宽度,以及另一个我将保存在新变量中的屏幕高度和宽度


我需要它在不同的屏幕上以kiosk模式打开两个浏览器屏幕。有人能帮我吗?

我没有注意到您使用的是旧版本的Windows PowerShell。
(我建议您更新到最新版本的Windows PowerShell 5.1或更高版本:使用)

无论如何,对于PowerShell 3.0,您应该能够做到:

$Screens = Get-WmiObject win32_desktopmonitor
$Screen2 = $Screens | Where-Object { $_.DeviceID -eq DesktopMonitor2 }
$Width2 = $Screen2.ScreenWidth
$Height2 = $Screen2.ScreenHeight

不要试图从一个物体上移除某些东西,想想你想保留什么。类似于:
$screen1 | Where Object Device ID-eq DesktopMonitor2 |选择Object-Property ScreenHeight,ScreenWidth
甚至更容易将对象作为一个整体保存:
$Screen2=$screen1 | Where Object Device ID-eq DesktopMonitor2
,并在需要时使用这些属性,例如:
$Screen2.屏幕高度
听起来你需要
会员访问操作员。如果
$screen1
描述了一个变量,该变量包含一个具有
ScreenHeight
属性的对象,那么
$screen1.ScreenHeight
将解析为所述属性值-因此,如果您想将该值本身存储在一个新变量中,请执行
$ScreenHeight=$screen1.Height
,这就是我现在的状态点<代码>$Screen=Get WmiObject win32|desktopmonitor$ScreenHeight=$ScreenHeight$ScreenWidth=$Screen.ScreenWidth$Screen1Width=$ScreenWidth |选择对象-第一个1$Screen2Width=$ScreenWidth |选择对象-跳过1$Screen2Height=$ScreenHeight |选择对象-跳过1。使用
Where Object DeviceID-eq DesktopMonitor2的iRon的东西不知何故不起作用。如果有人知道原因,我会很高兴,因为这对我来说是一个完美的解决方案。这样我就不必用
选择对象-Skip1
-First 1
来实现这一点。这个脚本将运行的计算机是一台笔记本电脑,所以当它打开时,这个脚本就不再工作了。。。