Author Posts

February 21, 2014 at 4:19 am

Hi all,

I'm trying to get to grips with formatting. I decide to mess around with another script I had been using that works great. I've copied part of it and made some changes to simplify it for learning. I've run into a problem and was hoping to pick your brains.

Here's what I'm working with.

$fmtbios =@{label="BIOS" ;alignment="left" ;width=5 ;Epression={$_.SMBIOSBIOSVersion};}
$fmtcompany =@{label="Company" ;alignment="left" ;width=10 ;Epression={$_.Manufacturer};}
$fmtbiosdate =@{label="BIOS Date" ;alignment="left" ;width=38 ;Epression={$_.Name};}
$fmtserial =@{label="Serial #" ;alignment="left" ;width=7 ;Epression={$_.SerialNumber};}
$fmtversion =@{label="Version" ;alignment="left" ;width=17 ;Epression={$_.Version};}

$bios = Get-WmiObject win32_bios

Write-Output $bios | Format-Table $fmtbios, $fmtcompany, $fmtbiosdate, $fmtserial, $fmtversion | out-file c:\fortmattest.txt

I get and error message stating

Format-Table : Illegal key Epression
At line:9 char:22
+ Write-Output $bios | Format-Table $fmtbios, $fmtcompany, $fmtbiosdate, $fmtseria ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Format-Table], NotSupportedException
+ FullyQualifiedErrorId : DictionaryKeyIllegal,Microsoft.PowerShell.Commands.FormatTableCommand

I've no doubt that I'm being stupid but as you guys are always so helpful I thought I would see what info you can provide.

Thanks!

February 21, 2014 at 4:22 am

$fmtbios =@{label=”BIOS” ;alignment=”left” ;width=5 ;Epression={$_.SMBIOSBIOSVersion};}

should be

$fmtbios =@{label=”BIOS” ;alignment=”left” ;width=5 ;Expression={$_.SMBIOSBIOSVersion};}

You have typo – Epression should be Expression

February 21, 2014 at 5:13 am

Oh no, hahah, thanks Richard.

Do you know what's worse, when I was cutting & pasting the error message into this thread I thought to myself "hmmm, it looks like that should be expression". I guess now I should think PowerShell doesn't make mistakes, users do!

On the plus side, now I've corrected the typo I get the expected output.

Thanks again, I'll no doubt have more formatting questions soon.