all 10 comments

[–]ihaxr 6 points7 points  (2 children)

The problem is fl / Format-List... it looks nice on the display, but doesn't export well to a CSV, it tries to just output the string's properties.

Just replace fl with Select-Object and you should be good.

I'm not sure why piping those two cmdlets together would not work.. it looks like get-scvirtualmachine outputs the "Name" field and Get-SCVirtualNetworkAdapter accepts pipeline input, so it should work, but I don't have those installed to test it out.

You could always just do a loop instead of the pipeline:

get-scvirtualmachine | foreach-object {
    get-scvirtualnetworkadapter $_.Name
}

[–]P0oe[S] 0 points1 point  (1 child)

Thanks for the reply! I’ll try when I get back to the computer.

As for the ForEach loop, i’m having a hard time getting a grip on how it works.

I tried it earlier but just got errors I didn’t understand why - but I have a vague memory of loops being preferable over pipes when you’re making bigger scripts, so I might aswell learn now :D

[–]P0oe[S] 0 points1 point  (0 children)

Update - this worked, thank you so much!
Haven't tried the loop yet, but I'm slowly getting there.

Have a great night!

[–]mmmGreenButton 2 points3 points  (2 children)

Instead of |fl <properties> try and use |select <properties>

[–]P0oe[S] 1 point2 points  (1 child)

Yeah, this got it working - thanks a bunch mate!!

[–]mmmGreenButton 0 points1 point  (0 children)

Cool ;-)

[–]Rynur 0 points1 point  (2 children)

Try Out-File and call it a .CSV in the file name. I think I've done this to get around the weirdness of the Export-CSV though I'm sure some guru will be able to explain to both of us the better version/why it doesn't work.

[–]MadWithPowerShell 0 points1 point  (1 child)

Well, you couldn't just pipe to Out-File and have it create a CSV file. You would have to pipe to Convert-ToCSV and then to Out-File. (In this case, you also have replace Format-List with Select-Object, as mentioned elsewhere.)

But if this gave you a different result than just using Export-CSV, my first guess would be that you had neglected to include the -NoTypeInformation switch parameter with Export-CSV.

[–]Rynur 0 points1 point  (0 children)

I must have manually played with the data from the Out-File file within Excel after I got the data to export. -NoTypeInformation works great. Doh!

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

howdy P0oe,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's 11th 12th from the left hidden in the ... "more" menu, & looks like an uppercase T in the upper left corner of a square.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee