Search code examples
powershellvirtual-machinevirtualbox

How to find specific text in a file with PowerShell?


in general, the script is designed to search for all virtual machines running on Windows.

I'd like to find all the specific text files, it's exactly OSType="Win..." My problem is that I don't know how to make it find words that contain OSType="Win..." The problem is that it's written with "" in the file. This is my code:

Get-ChildItem -Path C:\Users\*vbox -recurse |  Select-String -Pattern 'OSType="Windows7_64"' -List | Select Path | Out-File -FilePath C:\Users\Public\ProcessKurdeExecuted.txt

Using * or % does not work

...Select-String -Pattern 'OSType="Windows*"'...
...Select-String -Pattern 'OSType="Windows%"'...

Solution

  • Documentation about regular expression is https://learn.microsoft.com/fr-fr/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-7

    You should try

    ...Select-String -Pattern 'OSType="Windows.*"'...