如何使用powershell从命令输出中提取值

时间:2013-09-17 08:42:38

标签: windows powershell monitoring raid

我正在尝试使用arcconf cli和power shell进行监控,以获得Adaptec raid阵列状态。 无法弄清楚如何从power shell中的命令返回字符串中获取最后一个值。

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

   Defunct disk drive count                 : 0

我需要从命令输出中获取0值。

2 个答案:

答案 0 :(得分:0)

将结果拆分为字符':'并取第二部分。像

这样的东西
((.\arcconf.exe getconfig 1 | select-string -pattern "Defunct disk drive count") -split ':')[1]

答案 1 :(得分:0)

试试这个:

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