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 - Import-CSV piped hashtable access

Reply
 
Old 12-27-2006   #1 (permalink)
Terry E Dow


 
 

Import-CSV piped hashtable access

Howdy,

I've been working on a filter that takes a piped input from Import-CSV,
merges additional columns, and is redirected to Export-CSV.

Import-CSV | myMerge-CSV | Export-CSV

It is my beleive that Import-CSV creates a hashtable with the column
headings as key fields. While in the myMerge-CSV function/filter I can not
convert $_ to a native hashtable or System.Collections.Hashtable. I can
convert to string "@{key1=value1; key2=value2}", but can not add this to
local hashtable being merged within the function.


My System SpecsSystem Spec
Old 12-27-2006   #2 (permalink)
Rob Campbell


 
 

RE: Import-CSV piped hashtable access

I just did a gm on an imported csv, and it appears that rather than creating
a hash table, it's creating a string of custom ps objects, with note
properties for each of the column headings.

I believe a .csv is a multi-valued array, whereas a hashtable is single
valued.

"Terry E Dow" wrote:

> Howdy,
>
> I've been working on a filter that takes a piped input from Import-CSV,
> merges additional columns, and is redirected to Export-CSV.
>
> Import-CSV | myMerge-CSV | Export-CSV
>
> It is my beleive that Import-CSV creates a hashtable with the column
> headings as key fields. While in the myMerge-CSV function/filter I can not
> convert $_ to a native hashtable or System.Collections.Hashtable. I can
> convert to string "@{key1=value1; key2=value2}", but can not add this to
> local hashtable being merged within the function.
>

My System SpecsSystem Spec
Old 12-29-2006   #3 (permalink)
Jacques Barathon [MS]


 
 

Re: Import-CSV piped hashtable access

"Rob Campbell" <RobCampbell@discussions.microsoft.com> wrote in message
news:74EFD865-9A53-4DB7-9935-B29A0C563456@microsoft.com...
>I just did a gm on an imported csv, and it appears that rather than
>creating
> a hash table, it's creating a string of custom ps objects, with note
> properties for each of the column headings.


Right. This example will illustrate it with what Terry is trying to achieve:

PS> type liste.csv
Image,FirstName,LastName
D:\EXPORT\image0001.tif,JEAN,VALJEAN
D:\EXPORT\image0002.tif,LOUIS,GEORGES
D:\EXPORT\image0003.tif,FELIX,LOUIS

PS> filter merge-csv {
>> add-member -in $_ NoteProperty FullName "$($_.FirstName)
>> $($_.LastName)" -passthru
>> }
>>

PS> import-csv liste.csv | merge-csv

Image FirstName LastName
FullName
----- ------ ---
--------
D:\EXPORT\image0001.tif JEAN VALJEAN
JEAN VALJEAN
D:\EXPORT\image0002.tif LOUIS GEORGES
LOUIS GEORGES
D:\EXPORT\image0003.tif FELIX LOUIS
FELIX LOUIS

PS> import-csv liste.csv | merge-csv | export-csv liste2.csv -notype
PS> type liste2.csv
Image,FirstName,LastName,FullName
D:\EXPORT\image0001.tif,JEAN,VALJEAN,"JEAN VALJEAN"
D:\EXPORT\image0002.tif,LOUIS,GEORGES,"LOUIS GEORGES"
D:\EXPORT\image0003.tif,FELIX,LOUIS,"FELIX LOUIS"

Hope that helps,
Jacques

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Return from a piped foreach in function PowerShell
I can't access this hashtable PowerShell
Working with Piped output PowerShell
String formatting of piped dates PowerShell
Any limit to the size of a .NET object that can be piped from one cmdlet to another? PowerShell


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