Hi all. I have next loop (it's a part of script):
$word = New-Object -ComObject Word.Application $word.Visible = $false $number = 0 foreach ($file in $docs) { # м м м $name = $file.Name ++$number Write-Verbose "$name `t`t ( $number $count)" -Verbose $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatFilteredHTML"); # м $doc = $word.Documents.Open($file.FullName) # м м html $pdf_file = $path_html + "\" + $doc.Name # м ( pdf- м doc) $pdf_file = [System.IO.Path]::ChangeExtension($pdf_file, '.htm') # м $doc.saveas([ref]"$pdf_file", [ref]$saveFormat); # м $doc.Close() }
It converts .doc (.docx) files to .html using Word. Sometimes the file is not converted and script hangs. How can I add maybe timeout to this loop if step does not end for 30 seconds -> close file and begin next step(file). Or maybe own version. Thank you very much for help.