![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||