0

I'm trying to split a list of name properties after the verb/hyphen and got it to work but I had to save to a file first.

I got it to work like this - Grab the Name properties and add them to a file -

Get-Command -Module Posh-SSH | Format-Table Name | out-file posh_ssh

then split list at the '-'

Get-Content .\posh_ssh | % {$_.split("-")[1]}

But is there a way to do it on one line like this? I don't understand why this didn't work.

Get-Command -Module Posh-SSH | Format-Table Name |  % {$_.split("-")[1]}

Thanks!

JohnRain
  • 41
  • 2
  • 9
  • Thanks Matt, I didn't realize format-table was the key to it. Really need someplace to ask newbie questions like the difference between passthru and tee – JohnRain Oct 02 '16 at 19:18

1 Answers1

1

Format is a formatter cmdlet, it should never be used anywhere else than the last section of a pipeline, since it doesn't pass "true" objects on to the pipeline. What you can do instead is to use select-object to grab the thing you want, like so (replaced module name with a module I had on my own computer):

Get-Command -Module microsoft.powershell.management | select-object -expand Name | % {$_.split("-")[1]}

That said, for this particular question, be aware that the objects outputted by get-command are rich objects by themselves, and contain a "noun" attribute which is what I'm assuming you're ultimately after: Get-Command -Module microsoft.powershell.management | select-object -ExpandProperty verb

Trondh
  • 3,221
  • 1
  • 25
  • 34