I have to go through thousands of documents looking for a string. When I do, the word document pops up on screen and then disappears after the object is removed.
There is a parameter of the Documents.OpenNoRepairDialog
method that is at position 13 to control the visibility. I cannot get any combination to work beyond the 3 parameters that are listed in the code. Is there a way to keep these documents from being visible when the code is run and turning my screen into a strobe light?
$Doc = $Word.Documents.OpenNoRepairDialog($file,$false,$true)
is the part that I need help with. I get errors when trying to add further argument such as $null
.
$Word = New-Object -comobject Word.Application
$Word.Visible = $false
$word.DisplayAlerts = "wdAlertsNone"
$Doc = $Null
$DocContent = $Null
$Doc = $Word.Documents.OpenNoRepairDialog($file,$false,$true)
$DocContent = $Doc.Content.Text | Select-String -Pattern $Using:SearchStrings
If($DocContent)
{
Write-Verbose "Match in $_ for Word" -Verbose
Write-Output "Match in $_" | Out-File -FilePath $Using:OutputFilePath -Append
}
Else
{
Write-Verbose "No Match" -Verbose
}
$Word.Documents.Close()
$Word.Quit()
While([System.Runtime.InteropServices.Marshal]::ReleaseComObject($DocContent)){}
While([System.Runtime.InteropServices.Marshal]::ReleaseComObject($Doc)){}
While([System.Runtime.InteropServices.Marshal]::ReleaseComObject($Word)){}
Remove-Variable -Name DocContent
Remove-Variable -Name Doc
Remove-Variable -Name Word