I need to have a word document count each time a doctor name is matched for yesterday. For example, there is a file share with 100 word document reports. I want the script to go through all 100 reports. If it sees “John Q. Smith” and the date & time was YESTERDAY, add 1 to the csv file that is counting. I can provide a sample word document report too if it will help.
I have a directory of word documents. Each word document has two strings of text like this:
Dictated by: John Q. Smith, M.D. on 03/04/2019 at 8:26
This report was verified electronically by John Q. Smith on 03/04/2019 at 8:37
It’s possible that the report word document was opened and ammended or an addendum was done. In that case, there will be four strings of text like this located in different places in the word document:
Dictated by: John D. Doe, M.D. on 03/01/2019 at 9:00
This report was verified electronically by John D. Doe on 03/01/2019 at 9:00
Dictated by: John Q. Smith, M.D. on 03/04/2019 at 8:26
This report was verified electronically by John Q. Smith on 03/04/2019 at 8:37
Is doctor name found? Yes or No, if yes then AND
Is date on dictated AND verified line YESTERDAY? yes or No, if yes, then…
Sure you can do this, but your script that you posted shows no calls to MSWord at all.
PS can read text based files without issue, any other file type requires you to use the DOM of that document.
Use an Easy PowerShell Command to Search Files for Information
https://devblogs.microsoft.com/scripting/use-an-easy-powershell-command-to-search-files-for-information
A quick search of the web with the string ‘powershell search for string in ms word’, would show you several result to leverage and tweak to your needs.
For Example:
Beginning with PowerShell and Word
https://learn-powershell.net/2014/12/31/beginning-with-powershell-and-word
Find All Word Documents that Contain a Specific Phrase
Weekend Scripter: Manipulating Word and Excel with PowerShell
There is even a module on the MS PowerShellGallery.com site, specifically for dealing with MSOffice documents.
Find-Module -Name '*word*', '*excel*'
<#
Find-Module -Name '*word*', '*excel*'
Version Name Repository Description
------- ---- ---------- -----------
0.6.0 PSWriteWord PSGallery Simple project to create Microsoft Word in PowerShell without having Office installed.
...
1.2.1 WordDoc PSGallery Generate Word Documents directly from PowerShell, visit project site https://shaneho...
...
0.6 PSWord PSGallery This module was created to automate the creation and manipulation of Word Documents.
...
5.4.5 ImportExcel PSGallery PowerShell module to import/export Excel spreadsheets, without Excel....
1.0.2 PSExcel PSGallery Work with Excel without installing Excel
0.0.16 PSWriteExcel PSGallery Little project to create Excel files without Microsoft Excel being installed.
18.0.68... ExcelCmdlets PSGallery CData Cmdlets for Excel
18.0.68... ExcelServicesCmdlets PSGallery CData Cmdlets for Excel Services
0.6.6 ExcelPSLib PSGallery Allow simple creation and manipulation of XLSX file
...
#>
You also have an syntax error in your script (easily fixable). Open it in the PowerShell ISE to see them or VSCode if that is your preference.
Also, you you wan tot track amends, then that means track changes should be enabled in the doc, and you just look for those. Which has already been talked about on the site. See this Q&A.
Track changes in MS Word
https://powershell.org/forums/topic/track-changes-in-ms-word