【发布时间】:2021-03-09 01:33:35
【问题描述】:
我有一个包含多个 Excel 文件的文件夹。我想搜索一个像“2501”这样的字符串,并找到我的哪个文件包含这个字符串,然后将它的文件名输出到一个文件(或显示它)。我写了一些脚本并用谷歌搜索但没有找到答案。
这是我写的:
$Location = "C:\1.xlsx"
$SearchStr = "Mike"
$Sel = Select-String -pattern $SearchStr -path $Location
If ($Sel -eq $null)
{
write-host "$Location does not contain $SearchStr" -ForegroundColor Cyan
}
Else
{
write-host "Found $SearchStr `n$Se in $Location"
}
Write-host "end" -ForegroundColor Yellow
这只有在我指定一个 txt 文件时才有效,它不适用于 Excel。
【问题讨论】:
-
另一个适用于 txt 文件的示例>>Get-Content c:\scripts\test.txt |选择字符串“失败”
标签: excel powershell