Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - -f format Format-Table Format-List against Select

Reply
 
Old 11-24-2008   #1 (permalink)
Personne


 
 

-f format Format-Table Format-List against Select

For some reason I need to rename a column within a select

Get-WmiObject win32_SystemEnclosure -ComputerName SD-IT003
it returns SerialNumber

But I do not like this label, I want to rename it

so
Get-WmiObject win32_SystemEnclosure -ComputerName $p | ft @{Expression=
{$_.SerialNumber};Label="SN"}
--> This works really well, but instead of renaming the column in FT,
I need to rename it during a select

So I tried this:

Get-WmiObject win32_SystemEnclosure -ComputerName $p | select @
{Expression={$_.SerialNumber};Label="SN"} | ft *

but it returns
Select-Object : Illegal key Label
At line:1 char:61
+ Get-WmiObject win32_SystemEnclosure -ComputerName $p| select <<<< @
{Expression={$_.SerialNumber};Label="SN"}

Why is that ? is there a way to fix it ?

My System SpecsSystem Spec
Old 11-24-2008   #2 (permalink)
Personne


 
 

Re: -f format Format-Table Format-List against Select

My goal is to do this

$p=get-qadcomputer -name sd-*
$p | foreach {
gwmi win32_operatingsystem -ComputerName $_.name | select
CSName,caption,CSDVersion,version,Description,SerialNumber
#gwmi Win32_WindowsProductActivation -ComputerName $_.name | select
ProductID
gwmi Win32_ComputerSystem -ComputerName $_.name | select
Domain,Manufacturer,Model,UserName
gwmi win32_bios -ComputerName $_.name | select SerialNumber
gwmi win32_SystemEnclosure -ComputerName $_.name | select SerialNumber
} | ft *

but as you can see I do have 3 requests returning a Serialnumber, but
I would like to return a table with SN1,SN2 and SN3


My System SpecsSystem Spec
Old 11-24-2008   #3 (permalink)
Hal Rottenberg [MVP]


 
 

Re: -f format Format-Table Format-List against Select

Personne wrote:
Quote:

> --> This works really well, but instead of renaming the column in FT,
> I need to rename it during a select
>
> So I tried this:
>
> Get-WmiObject win32_SystemEnclosure -ComputerName $p | select @
> {Expression={$_.SerialNumber};Label="SN"} | ft *
The Select-Object cmdlet uses the key "Name" instead of "Label". I struggled a
long time with the logic of this and eventually squared it with my brain by
referring to the fields created by Select-Object as "real properties" and
properties have names, as opposed to Format-* which is merely for display
purposes, so "label" implies a more temporary connotation.

HTH

--
$signature = "Hal Rottenberg, MVP - Admin Frameworks"
$projects = @{ title = "Blog Author"; url = "http://halr9000.com" },
@{ title = "Co-host"; url = "http://powerscripting.net" },
@{ title = "Community Director"; url = "http://PowerShellCommunity.org" },
@{ title = "Psi Webmaster"; url = "http://psi-im.org" }
My System SpecsSystem Spec
Old 11-24-2008   #4 (permalink)
Personne


 
 

Re: -f format Format-Table Format-List against Select

$p="."
$with_label = @{Expression={$_.SerialNumber};Label="SN1"}
$with_name = @{Expression={$_.SerialNumber};Name="SN2"}

gwmi win32_SystemEnclosure -ComputerName $p | ft $with_label
gwmi win32_SystemEnclosure -ComputerName $p | select $with_name

Works Perfect
Thank you
My System SpecsSystem Spec
Old 11-25-2008   #5 (permalink)
OldDog


 
 

Re: -f format Format-Table Format-List against Select

On Nov 24, 1:01*pm, Personne <cpdiv...@xxxxxx> wrote:
Quote:

> $p="."
> $with_label = @{Expression={$_.SerialNumber};Label="SN1"}
> $with_name = @{Expression={$_.SerialNumber};Name="SN2"}
>
> gwmi win32_SystemEnclosure -ComputerName $p | ft $with_label
> gwmi win32_SystemEnclosure -ComputerName $p | select $with_name
>
> Works Perfect
> Thank you
You must be working with Dell computers,
for HP and IBM's you have to look in Win32_BIOS for the SerialNumber
or Win32_ComputerSystemProduct for the IdentifyingNumber

1# gwmi Win32_ComputerSystemProduct


IdentifyingNumber : MXL60207Q5
Name : HP Compaq dc7600 Small Form Factor
Vendor : Hewlett-Packard
Version :
Caption : Computer System Product



2# gwmi Win32_BIOS


SMBIOSBIOSVersion : 786D1 v01.03
Manufacturer : Hewlett-Packard
Name : Default System BIOS
SerialNumber : MXL60207Q5
Version : COMPAQ - 20050518





OldDog
My System SpecsSystem Spec
Old 11-25-2008   #6 (permalink)
OldDog


 
 

Re: -f format Format-Table Format-List against Select

On Nov 24, 1:01*pm, Personne <cpdiv...@xxxxxx> wrote:
Quote:

> $p="."
> $with_label = @{Expression={$_.SerialNumber};Label="SN1"}
> $with_name = @{Expression={$_.SerialNumber};Name="SN2"}
>
> gwmi win32_SystemEnclosure -ComputerName $p | ft $with_label
> gwmi win32_SystemEnclosure -ComputerName $p | select $with_name
>
> Works Perfect
> Thank you
I have found that I need to use win32_SystemEnclosure for Dell Servers

HP servers will give you the serial number in three different places;

gwmi Win32_BIOS -computername server1
as SerialNumber

Or

gwmi Win32_ComputerSystemProduct -computername Server1

as IdentifyingNumber

as well as

gwmi win32_SystemEnclosure -computername Server1
as SerialNumber

OldDog
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Windows Mail format bar doesn't format color, size, justification Browsers & Mail
RE: How to convert Table-Format Data to CSV-Format? PowerShell
RE: How to convert Table-Format Data to CSV-Format? PowerShell
RE: How to convert Table-Format Data to CSV-Format? PowerShell
Help! DVD format error: "Windows was unable to complete the format Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46