我有以下命令:

Get-WmiObject win32_service |
  ? {$_.Name -like '*Front*'} |
    ? {$_.PathName -like '*logdir*'} |
      select Name, PathName
其输出类似于:
Frontapp (Frontapp1) D:\Application\Frontapp\Frontapp.exe -service  -dbType mssql -ORBSvcConf D:\Frontapp83\Frontapp\svc.conf -connections 5 -connectionPoolSize 64 -logdir D:\Frontapp\log1

Frontapp (Frontapp0) D:\Frontapp83\Frontapp\Frontapp.exe -service  -dbType ora -ORBSvcConf D:\Frontapp83\Frontapp\svc.conf -connections 35 -connectionPoolSize 64 -logdir D:\Frontapp\log0
我如何从输出中删除信息,仅获得-logdir路径。
所需的输出:
Frontapp (Frontapp1) D:\Frontapp\log1

Frontapp (Frontapp0) D:\Frontapp\log0

最佳答案

使用calculated property:

Get-WmiObject win32_service |
  ? { $_.Name -like '*Front*' -and $_.PathName -like '*logdir*' } |
    select Name, @{ n='LogDir'; e={ $_.PathName -replace '^.+logdir\s+' } }

07-25 20:21