我在网上找到了一个很棒的Powershell脚本,让我们搜索Excel文档的内容以查找特定单词,并根据需要对其进行了修改。查找MS Word的方法
现在我想添加用于搜索Word文档内容的功能,但是我正在努力弄清楚我需要使用的方法(?)。
请原谅我,如果我得到关于类和方法的术语错误,这对我来说是新的领域。
这个为脚本的现有代码:
$SearchDest = Read-Host "Where do you want to search?"
$Destination = 'C:\temp'
$SearchText = 'myword'
$Excel = New-Object -ComObject Excel.Application
$Files = Get-ChildItem "$SearchDest\*.xlsx" | Select-Object -Expand FullName
$counter = 1
ForEach($File in $Files) {
Write-Progress -Activity "Checking: $file" -Status "File $counter of $($files.count)" `
-PercentComplete ($counter * 100/$files.Count)
$Workbook = $Excel.Workbooks.Open($File)
If($Workbook.Sheets.Item(1).Range("A:Z").Find($SearchText)) {
$Workbook.Close($false)
Copy-Item -Path $File -Destination $Destination
"Copied $file to $destination"
break
}
$Workbook.Close($false)
$counter++
}
,我试图找出相当于$Excel.Workbooks.Open($File)
等是。
您是否尝试过寻找的Word基于脚本,让你正在寻找方法? – Matt