0

I have the following code

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

It outputs:

Value

--

VirtualMachine-vm-

The error file has VirtualMachine-vm-12345 but will change so I need to find not an exact match.

lebelinoz
  • 4,890
  • 10
  • 33
  • 56
Henry B
  • 33
  • 1
  • 8

1 Answers1

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

I figured it out How do I run Get-VM -ID on this value?

Update here is the answer:

$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
Henry B
  • 33
  • 1
  • 8