如何从 Get-WMIObject 输出 powershell 中删除多余的行 [英] How to remove extra lines from Get-WMIObject output powershell
问题描述
我正在运行以下查询以获取视频驱动程序版本号
I am running the following query to get the video driver version number
Get-WmiObject Win32_videoController | where {$_.Name -like "Nvidia*"} | Format-table -HideTableHeaders DriverVersion
它返回我想要的数据加上大约 4 行.输出前 1 个,输出后 3 个.它看起来不会在帖子中正确显示.
It returns the data I want plus about 4 extra lines. One before the output and 3 after. It doesn't look like it's going to show up properly in the post.
PS F:\>
Get-WmiObject Win32_videoController | where {$_.Name -like "Nvidia*"} | Format-table -HideTableHeaders DriverVersion
9.18.13.3250
PS F:\>
推荐答案
如果要确定驱动程序版本,请忘记 Format-Table
.只需这样做:
If you want to determine the driver version, forget about Format-Table
. Simply do this:
Get-WmiObject Win32_VideoController -Filter "Name LIKE 'Nvidia%'" |
Select-Object -Expand DriverVersion
注意:您还可以为 Get-WmiObject
使用别名 gwmi
,为 使用别名
.但是请注意,根据您的环境,在脚本执行期间可能不存在别名.它们基本上是一种减少交互式控制台所需输入量的方法.select
选择对象
Note: You can also use the aliases gwmi
for Get-WmiObject
and select
for Select-Object
. Beware, though, that aliases may not be present during script execution depending on your environment. They're basically a means to reduce the amount of typing required in an interactive console.
这篇关于如何从 Get-WMIObject 输出 powershell 中删除多余的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!