How to remove extra lines from Get-WMIObject outpu

2019-02-25 22:30发布

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:\> 

2条回答
Summer. ? 凉城
2楼-- · 2019-02-25 22:49

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.

查看更多
再贱就再见
3楼-- · 2019-02-25 22:52

Not sure exactly if this is what you want but give this a try. This will only display the "Unique" driver versions. This will get rid of the dupe entrys

Get-WmiObject Win32_videoController | Where {$_.Name -like "Nvidia*"} | Select-Object DriverVersion -Unique | Format-Table -HideTableHeaders
查看更多
登录 后发表回答