Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions Links


SQL Server DBA Jobs

How to Convert Microsoft Word Format to HTML using Powershell

15 June,2012 by Tom Collins

Question : I have a list of Microsoft Word Docs , which need to be converted into html .   How can I do this with Powershell?    I've already checked ConvertTo-Html , but it's a different purpose

Answer:  Converting a  list of Microsoft Word documents  is repetitive and time consuming.  Powershell creates a new com object , which filters the Word Doc into html format.

The assembly loads  the type [Microsoft.Office.Interop.Word.WdSaveFormat]

This script reads all Word documents in the $srcFiles path and outputs them into the $htmlOutputPath.

Note: the file is saved with the base name. For example, if the word doc is called "test.docx"  the file is saved as "test.html"  


$wdTypes = Add-Type -AssemblyName 'Microsoft.Office.Interop.Word' -Passthru
$srcFiles = Get-ChildItem $docSrc -filter "*.doc"
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatFilteredHTML"); 
$wordApp = new-object -comobject word.application 
$wordApp.Visible = $False
function saveashtml
        $openDoc = $$doc.FullName); 
$openDoc.saveas([ref]"$htmlOutputPath\$saveas.html", [ref]$saveFormat); $openDoc.close(); } ForEach ($doc in $srcFiles) { Write-Host "Converting to html :" $doc.FullName saveashtml $doc = $null } $wordApp.quit();

Thanks to Bhargav Shukla for function concepts on this link

 Read More

Powershell to HTML

Powershell sql server security audit

SQL Server – Send email using Powershell - SQL Server DBA

SQL Server - Powershell and SQL Error Logs

SQL Server DBA Top 10 automation tasks

SQL Server - Top 10 DBA mistakes


Author: Tom Collins (


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment on How to Convert Microsoft Word Format to HTML using Powershell | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer