0

When I want to choose a specific text from output within powershell I could use

select-string -Pattern "whatever:"

And it would print out the whatever column. But when I try the same thing on this output it instead prints out the row instead of the column.

So I do like this:

> /c0 show | select-string -Pattern "EID:Slt"

And instead of showing the column it shows this:

> EID:Slt DID State DG Size Intf Med SED PI SeSz Model        
> Sp

The only way I could figure it out was to replace all the characters with empty space but it's kind of messy to do so, anyone else can help with a input?

How I try to make it display the output text: 32:1, 32:2, 32:3, [...]

Controller = 0
Status = Success
Description = Show Drive Information Succeeded.


Drive Information :
=================

--------------------------------------------------------------------------
EID:Slt DID State DG     Size Intf Med SED PI SeSz Model               Sp 
--------------------------------------------------------------------------
32:0      0 Onln   0 3.637 TB SATA HDD N   N  512B ST4000NM0033-9ZM170 U  
32:1      1 Onln   1 3.637 TB SATA HDD N   N  512B ST4000NM0033-9ZM170 U  
32:2      2 Onln   1 3.637 TB SATA HDD N   N  512B ST4000NM0033-9ZM170 U  
32:3      3 Onln   1 3.637 TB SATA HDD N   N  512B ST4000NM0033-9ZM170 U  
32:4      4 Onln   1 3.637 TB SATA HDD N   N  512B ST4000NM0033-9ZM170 U  
32:5      5 Onln   1 3.637 TB SATA HDD N   N  512B ST4000NM0033-9ZM170 U  
32:6      6 Onln   1 3.637 TB SATA HDD N   N  512B ST4000NM0033-9ZM170 U  
32:7      7 Onln   1 3.637 TB SATA HDD N   N  512B ST4000NM0033-9ZM170 U  
--------------------------------------------------------------------------
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
mr Joe
  • 9
  • 1
  • 6
  • You seem to be approaching powershell like cmd etc where the output are just strings on the screen to be manipulated; what is `/c0 show`? If I run it I just get an error, your answer may lie in viewing this output as the object it (hopefully) is. If you type in `/c0 show | gm` what can you see there? – Dizzy Feb 20 '18 at 09:08
  • It's a command line program from Dell run in cmd where you can RAID disks and other great stuff. But for doing so, I need the disks that are going to be raided. I managed to do it using Intels Rapid Storage command line interface because it was more straight forward so I thought about trying on my Dell Server which does not support Intel CLI. The command shows all harddrives on my PERC controller. I thought it would be easier to do it in powershell instead of creating batch files. Running the command shows the output pasted in the text above. Yeah, its because I've been using cmd alot latley – mr Joe Feb 20 '18 at 09:15
  • Ah ok, if its a 3rd party program it probably returns the output as a string, Janne's answer below should be what you need to do. – Dizzy Feb 20 '18 at 11:50

1 Answers1

1

Couldn't you just match the pattern of the data in the desired column? The first column seems to always be at the beginning of the line, have two digits followed by a colon and one digit. You could extract them with this:

Select-String -Pattern "^\d{2}:\d" -AllMatches | % { $_.Matches.Value }

To get the data from the whole table with property names from the header line, you'd better parse them as fixed length fields. But the above should be enough if that one column is all you need.

Janne Tuukkanen
  • 1,620
  • 9
  • 13
  • Thank you for the help, Ill have to read about it, I didnt know you could do so in Powershell. Thank you once again – mr Joe Feb 20 '18 at 11:52
  • What is happening after you pipe the output? Specifically ` | % { $_.Matches.Value }`. Is `%` shorthand for some PowerShell command? – oligofren Aug 16 '21 at 12:07
  • Nevermind, found https://stackoverflow.com/questions/22846596/what-does-percent-do-in-powershell – oligofren Aug 16 '21 at 12:16