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 - Duplicating import-csv with write-output

Reply
 
Old 11-27-2006   #1 (permalink)
Marco Shaw


 
 

Duplicating import-csv with write-output

Wondering if we can duplicate the output of import-csv using write-output
instead?

PS C:\> write-output "Country,Points" `
>> "U.S.A.,20" `
>> "Canada,10"|format-table -property country,points
>>

Country,Points
U.S.A.,20
Canada,10

PS C:\> gc country.csv
Country,Points
U.S.A.,20
Canada,10

PS C:\> import-csv country.csv

Country Points
------- ------
U.S.A. 20
Canada 10

I have a cmdlet (PowerGadget's out-map) that takes import-csv formatted
input, and I'm wondering if I can add some more smarts to the data input.

Can import-csv use scriptblocks? I'm not sure if that would do the trick
for me...



My System SpecsSystem Spec
Old 11-27-2006   #2 (permalink)
dreeschkind


 
 

RE: Duplicating import-csv with write-output

You can use Select-Object to create new custom psObjects.
In this example, Select-Object has gets an array of hashtables.
Each hashtable consists of an expression and a name for that column.

Write-Output "U.S.A.,20","Canada,10" |
Select @{e={$_.split(',')[0]};n='Country'},@{e={$_.split(',')[1]};n='Points'}

Country
Points
-------
------
U.S.A. 20
Canada 10

Also note that you don't need to use Write-Output, because the objects
(strings) get sucked into the pipeline anyway.

--
greetings
dreeschkind

"Marco Shaw" wrote:

> Wondering if we can duplicate the output of import-csv using write-output
> instead?
>
> PS C:\> write-output "Country,Points" `
> >> "U.S.A.,20" `
> >> "Canada,10"|format-table -property country,points
> >>

> Country,Points
> U.S.A.,20
> Canada,10
>
> PS C:\> gc country.csv
> Country,Points
> U.S.A.,20
> Canada,10
>
> PS C:\> import-csv country.csv
>
> Country Points
> ------- ------
> U.S.A. 20
> Canada 10
>
> I have a cmdlet (PowerGadget's out-map) that takes import-csv formatted
> input, and I'm wondering if I can add some more smarts to the data input.
>
> Can import-csv use scriptblocks? I'm not sure if that would do the trick
> for me...
>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Write-Output is bleeding into a pipe why PowerShell
Formatting output with write-host PowerShell
No output from write-output PowerShell
write-output array without C/R PowerShell
write whatif output to file 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