Source Code and Samples

Wednesday 14 February 2007

Search Strings In Word Documents

Description

Search Strings In Word Documents

Data Source

$SearchText = $args[0]
$word = new-object -ComObject "word.application"
$path = pwd
if ($args.length > 1) {
$docs = $args[1]
}
else {
$docs = "*.doc"
}
foreach ($a in $(get-childitem $docs -name)) {
$doc = $word.documents.open("$path\$a")
if ($doc.content.find.execute("$SearchText")) {
write-host $a
}
$doc.close();
}

No comments: