$phrase = $args[0];
$wd = new-object -activex "word.application";
$p = pwd;
if ($args.length > 1) {
$docs = $args[1];
} else {
$docs = "*.doc";
}
foreach ($a in $(get-childitem $docs -name)) {
$doc = $wd.documents.open("$p\$a");
if ($doc.content.find.execute("$phrase")) { write-host $a }
$doc.close();
}
Usage : save the above as, say,
FindStringsInWordDocs.msh and invoke
FindStringsInWordDocs.msh "This phrase" *.doc
\.doc
It emits the name of any document given (by default, all .doc files in the current working directory) that contain the string given as first argument. This works a good deal faster than the demo grep-string command does, for word documents, though that does also typically find strings as well. --
BradfordHull