I am trying to make a script that can find multiple strings in lots of files.
I have copied and altered the following script for my needs. It does only the MS word files.
How can I achieve the same for excel and pdf files?
Set-StrictMode -Version latest
$word = New-Object -ComObject Word.Application
$source = 'C:\test'
$destination = 'C:\test2'
$keyword1 = '25159'
$keyword2 = '2016'
$keyword3 = 'Examenplan'
$docs = Get-ChildItem -Path $source -Recurse | Where-Object {$_.Name -like '*.doc*'}
$charactersAround = 130
$counter = 0
foreach ($doc in $docs)
{
Write-Progress -Activity "Checking: $doc" -Status "File $counter of $($docs.count)" -PercentComplete ($counter*100/$docs.count)
$condition1 = $word.Documents.Open($doc.FullName).Content.Find.Execute($keyword1,$true,$true)
$condition2 = $word.Documents.Open($doc.FullName).Content.Find.Execute($keyword2,$true,$true)
$condition3 = $word.Documents.Open($doc.FullName).Content.Find.Execute($keyword3,$true,$true)
if ($condition1 -and $condition2 -and $condition3)
{
$word.Application.ActiveDocument.Close()
Copy-Item -Path $doc.FullName -Destination $destination
}
else
{
$word.Application.ActiveDocument.Close()
}
}