如何使用PowerShell查找文件中的特定文本?

问题描述 投票:0回答:2

通常,该脚本旨在搜索Windows上运行的所有虚拟机。

我想找到所有特定的文本文件,正是OSType =“ Win ...”。我的问题是我不知道如何使它查找包含OSType =“ Win ...”的单词。问题是它在文件中写有“”。这是我的代码:

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

使用*或%不起作用

...Select-String -Pattern 'OSType="Windows*"'...
...Select-String -Pattern 'OSType="Windows%"'...
powershell virtual-machine virtualbox
2个回答
0
投票

关于正则表达式的文档是https://docs.microsoft.com/fr-fr/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-7

您应该尝试

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

0
投票

我找到了解决方案:

$OSType = 'OSType="Windows*'
Get-ChildItem -Path C:\Users\*vbox -recurse |  Select-String -Pattern $OSType -List | Select Path | Out-File -FilePath C:\Users\Public\ProcessKurdeExecuted.txt
© www.soinside.com 2019 - 2024. All rights reserved.