How to use power shell to exctract values from command output

476 Views Asked by At

I'm trying to get Adaptec raid array status by using arcconf cli and power shell for monitoring. Can not figure out the way to get the last values from the command returned string in power shell.

PS C:\adaptec\msm\cmdline> .\arcconf.exe  getconfig  1  | select-string   -pattern "Defunct disk drive count"

   Defunct disk drive count                 : 0

I need to get the 0 value from command output.

2

There are 2 best solutions below

0
Loïc MICHEL On

split the result at the caracter ':' and take the second part. Something like

((.\arcconf.exe getconfig 1 | select-string -pattern "Defunct disk drive count") -split ':')[1]
0
Ansgar Wiechers On

Try this:

(.\arcconf.exe getconfig 1) -match 'defunct disk drive count\s+:\s+(\d+)'
$matches[1]