【问题标题】:Using Select-String (PowerShell) to find a word from error file使用 Select-String (PowerShell) 从错误文件中查找单词
【发布时间】:2017-09-19 13:33:56
【问题描述】:

我有以下代码

Select-String -path errors.log -Pattern 'VirtualMachine\s*-vm-' | %{$_.Matches 
| Select Value}

它输出:

Value

--

VirtualMachine-vm-

错误文件有 VirtualMachine-vm-12345 但会改变,所以我需要找到不完全匹配的。

【问题讨论】:

    标签: select-string


    【解决方案1】:
    Select-String -path errors.log -Pattern 'VirtualMachine\s*-vm-\d\d\d\d\d\d' | %{$_.Matches | Select Value}
    

    我想通了 如何在此值上运行 Get-VM -ID?

    更新 这是答案:

    $match = Select-String -path C:\errors.log -Pattern 'VirtualMachine\s*-vm-\d\d\d\d\d\d' | %{$_.Matches | Select -expand Value}
    
    Get-VM -id $match | ft -Property Name,ID -AutoSize
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 2023-03-11
      • 1970-01-01
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多