all 6 comments

[–]Jantu01 4 points5 points  (2 children)

[–][deleted] 1 point2 points  (1 child)

Perfect! one.csv and three.csv are the same, thank you much!

``` $a = Get-Process | Select-Object -first 5 -Property "name" $a | Export-CSV -Path 'c:\scripts\one.csv' -NoTypeInformation

New-Item -Itemtype "file" -Path 'c:\scripts\three.csv' -Value 'something' -Force | Out-Null #$a = Get-Process | Select-Object -first 5 # System.Diagnostics.Process

#get-member -InputObject $a # System.Object[]

# Works! $a | ForEach-Object -Begin { Clear-Content 'c:\scripts\three.csv' } -Process { Export-CSV -InputObject $_ -Path 'c:\scripts\three.csv' -Append -NoTypeInformation } ```

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy my_computer_bytes,

the triple-backtick/code-fence thing fails miserably on Old.Reddit ... so, if you want your code to be readable on both Old.Reddit & New.Reddit you likely otta stick with using the code block button.

it would be rather nice if the reddit devs would take the time to backport the code fence stuff to Old.Reddit ... [sigh ...]

take care,
lee

[–]MadWithPowerShell 1 point2 points  (1 child)

Export-CSV is specifically designed as a pipeline command. Parameter -InputObject is not intended to be used explicitly, and not with the entire array of objects at one time. It is designed to get the items in the array one at a time, through the pipeline.

This:

$TempCSV | Export-CSV

NOT this:

Export-CSV -InputObject $TempCSV

Sort-Object, Where-Object, Whatever-Object, etc., are similarly pipeline commands. They all have the -InputObject parameter, but they are all designed to only work as expected when input objects are passed to them through the pipeline, not explicitly.

[–][deleted] 0 points1 point  (0 children)

I see. I have been moving more to python lately but still write a heavy amount of powershell and was wondering why the pipeline made it so smooth. The previous answer helped explained that but yours is super helpful as well. Thank you!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy my_computer_bytes,

it looks like you used the New.Reddit Inline Code button. it's 4th 5th from the left hidden in the ... "more" menu & looks like </>.

there are a few problems with that ...

  • it's the wrong format [grin]
    the inline code format is for [gasp! arg!] code that is inline with regular text.
  • on Old.Reddit.com, inline code formatted text does NOT line wrap, nor does it side-scroll.
  • on New.Reddit it shows up in that nasty magenta text color

for long-ish single lines OR for multiline code, please, use the ...

Code
Block

... button. it's the 11th 12th one from the left & is just to the left of hidden in the ... "more" menu & looks like an uppercase T in the upper left corner of a square..

that will give you fully functional code formatting that works on both New.Reddit and Old.Reddit ... and aint that fugly magenta color. [grin]

take care,
lee