从 Powershell 中的变量中删除内容
Delete content from variable in Powershell
我的问题是,如何从变量中删除一些内容?我只想获取我的屏幕坐标。
所以我可以通过 $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 usingGet-CimInstance
)
无论如何,对于 PowerShell 3.0,您应该可以这样做:
$Screens = Get-WmiObject win32_desktopmonitor
$Screen2 = $Screens | Where-Object { $_.DeviceID -eq DesktopMonitor2 }
$Width2 = $Screen2.ScreenWidth
$Height2 = $Screen2.ScreenHeight
我的问题是,如何从变量中删除一些内容?我只想获取我的屏幕坐标。
所以我可以通过 $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 usingGet-CimInstance
)
无论如何,对于 PowerShell 3.0,您应该可以这样做:
$Screens = Get-WmiObject win32_desktopmonitor
$Screen2 = $Screens | Where-Object { $_.DeviceID -eq DesktopMonitor2 }
$Width2 = $Screen2.ScreenWidth
$Height2 = $Screen2.ScreenHeight