tags:

views:

26

answers:

1

Just getting started with Powershell and have a quick question. Trying to run this statement:

gwmi -query "select Description from Win32_OperatingSystem" | select-object Description

The results come back as:

Description
------------
My PC Name

But I just want MY PC Name. What else to I need to add to the statement to remove the label and just get the value? Thanks!

+4  A: 

Your output is going through (Format-Default and then) Format-Table, which adds that header. You can get rid of it by specifying Format-Table -HideTableHeaders ...

OR ... if you really just want the string, you can use any of these patterns:

(gwmi -query "select Description from Win32_OperatingSystem").Description
gwmi -query "select Description from Win32_OperatingSystem" | Select -Expand Description
gwmi -query "select Description from Win32_OperatingSystem" | ForEach{ $_.Description }
Jaykul
Thanks Jaykul, I really appreciate the insight as to why the header gets added in the first place in addition to the solution to my exact problem!
Jay