Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

wmi - 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

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:> 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...