{"id":1653,"date":"2010-07-28T20:27:30","date_gmt":"2010-07-29T04:27:30","guid":{"rendered":"http:\/\/www.bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/"},"modified":"2010-07-28T20:27:30","modified_gmt":"2010-07-29T04:27:30","slug":"how-to-convert-a-word-document-to-other-formats-using-powershell","status":"publish","type":"post","link":"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/","title":{"rendered":"How to convert a word document to other formats using PowerShell"},"content":{"rendered":"<p>I recently borrowed a <a href=\"http:\/\/www.sonystyle.com\/webapp\/wcs\/stores\/servlet\/ProductDisplay?catalogId=10551&amp;storeId=10151&amp;langId=-1&amp;productId=8198552921665921180\">Sony Reader Touch Edition<\/a> from someone I know to try it out. As I started using Sony\u2019s own library manager, I quickly got bored. I then tried open source <a href=\"http:\/\/calibre-ebook.com\">Calibre<\/a> which turned out to be a lot better interface but had a major flaw when it comes to supporting Sony Reader: It didn\u2019t support importing word documents in the library despite of Sont Reader\u2019s capability to read it. It can however import filtered html files which work can produce. Given my lazy nature, I did not want to convert a bunch of word documents I have by hand so I set out to write a PowerShell script to do the work for me.<\/p>\n<p>The script turned out to be much simpler than I thought. Here it is for everyone\u2019s benefit.<\/p>\n<pre class=\"brush: ps\">param([string]$docpath,[string]$htmlpath = $docpath)\n\n$srcfiles = Get-ChildItem $docPath -filter \"*.doc\"\n$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], \"wdFormatFilteredHTML\");\n$word = new-object -comobject word.application\n$word.Visible = $False\n\t\t\nfunction saveas-filteredhtml\n\t{\n\t\t$opendoc = $word.documents.open($doc.FullName);\n\t\t$opendoc.saveas([ref]\"$htmlpath\\$doc.fullname.html\", [ref]$saveFormat);\n\t\t$opendoc.close();\n\t}\n\t\nForEach ($doc in $srcfiles)\n\t{\n\t\tWrite-Host \"Processing :\" $doc.FullName\n\t\tsaveas-filteredhtml\n\t\t$doc = $null\n\t}\n\n$word.quit();\n<\/pre>\n<p>Save this code to convertdoc-tohtml.ps1 and you can run it on a set of word documents regardless of doc or docx extension. Also for efficiency I am using \u2013filter in Get-ChildItem instead of piping to where-object or using If statement in the script. Why? Because it says right in the help:<\/p>\n<blockquote>\n<p>\u201cFilters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.\u201d<\/p>\n<\/blockquote>\n<p>To run the script, you simple need to point it to a folder where your source document files are and provide output folder if you wish. If not provided, source folder will also be used as output folder. Here\u2019s how you can run it:<\/p>\n<pre class=\"brush: ps\">convertdoc-tohtml.ps1 -docpath \"C:\\Documents\" -htmlpath \"C:\\Output\"\n<\/pre>\n<p>If you want to know how the script can be transformed to save as different format, refer to wdSaveFormat Enumeration members on <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.office.interop.word.wdsaveformat(office.11).aspx\">MSDN<\/a>.<\/p>\n<p>Originally posted at http:\/\/blogs.technet.com\/bshukla<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently borrowed a Sony Reader Touch Edition from someone I know to try it out. As I started using Sony\u2019s own library manager, I quickly got bored. I then [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[19],"tags":[],"class_list":["post-1653","post","type-post","status-publish","format-standard","hentry","category-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to convert a word document to other formats using PowerShell - Bhargav&#039;s IT Playground<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to convert a word document to other formats using PowerShell - Bhargav&#039;s IT Playground\" \/>\n<meta property=\"og:description\" content=\"I recently borrowed a Sony Reader Touch Edition from someone I know to try it out. As I started using Sony\u2019s own library manager, I quickly got bored. I then [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Bhargav&#039;s IT Playground\" \/>\n<meta property=\"article:published_time\" content=\"2010-07-29T04:27:30+00:00\" \/>\n<meta name=\"author\" content=\"Bhargav\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bhargav\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/07\\\/28\\\/how-to-convert-a-word-document-to-other-formats-using-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/07\\\/28\\\/how-to-convert-a-word-document-to-other-formats-using-powershell\\\/\"},\"author\":{\"name\":\"Bhargav\",\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#\\\/schema\\\/person\\\/28f6d8c9b29f3a879483d65fc2ab5e26\"},\"headline\":\"How to convert a word document to other formats using PowerShell\",\"datePublished\":\"2010-07-29T04:27:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/07\\\/28\\\/how-to-convert-a-word-document-to-other-formats-using-powershell\\\/\"},\"wordCount\":305,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#\\\/schema\\\/person\\\/28f6d8c9b29f3a879483d65fc2ab5e26\"},\"articleSection\":[\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/07\\\/28\\\/how-to-convert-a-word-document-to-other-formats-using-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/07\\\/28\\\/how-to-convert-a-word-document-to-other-formats-using-powershell\\\/\",\"url\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/07\\\/28\\\/how-to-convert-a-word-document-to-other-formats-using-powershell\\\/\",\"name\":\"How to convert a word document to other formats using PowerShell - Bhargav&#039;s IT Playground\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#website\"},\"datePublished\":\"2010-07-29T04:27:30+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/07\\\/28\\\/how-to-convert-a-word-document-to-other-formats-using-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/07\\\/28\\\/how-to-convert-a-word-document-to-other-formats-using-powershell\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/bhargavs.com\\\/index.php\\\/2010\\\/07\\\/28\\\/how-to-convert-a-word-document-to-other-formats-using-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/bhargavs.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to convert a word document to other formats using PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#website\",\"url\":\"https:\\\/\\\/bhargavs.com\\\/\",\"name\":\"Bhargav's IT Playground\",\"description\":\"Passion for Technology. Power of Collaboration.\",\"publisher\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#\\\/schema\\\/person\\\/28f6d8c9b29f3a879483d65fc2ab5e26\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/bhargavs.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#\\\/schema\\\/person\\\/28f6d8c9b29f3a879483d65fc2ab5e26\",\"name\":\"Bhargav\",\"logo\":{\"@id\":\"https:\\\/\\\/bhargavs.com\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/bhargavs.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to convert a word document to other formats using PowerShell - Bhargav&#039;s IT Playground","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/","og_locale":"en_US","og_type":"article","og_title":"How to convert a word document to other formats using PowerShell - Bhargav&#039;s IT Playground","og_description":"I recently borrowed a Sony Reader Touch Edition from someone I know to try it out. As I started using Sony\u2019s own library manager, I quickly got bored. I then [&hellip;]","og_url":"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/","og_site_name":"Bhargav&#039;s IT Playground","article_published_time":"2010-07-29T04:27:30+00:00","author":"Bhargav","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Bhargav","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/#article","isPartOf":{"@id":"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/"},"author":{"name":"Bhargav","@id":"https:\/\/bhargavs.com\/#\/schema\/person\/28f6d8c9b29f3a879483d65fc2ab5e26"},"headline":"How to convert a word document to other formats using PowerShell","datePublished":"2010-07-29T04:27:30+00:00","mainEntityOfPage":{"@id":"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/"},"wordCount":305,"commentCount":0,"publisher":{"@id":"https:\/\/bhargavs.com\/#\/schema\/person\/28f6d8c9b29f3a879483d65fc2ab5e26"},"articleSection":["PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/","url":"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/","name":"How to convert a word document to other formats using PowerShell - Bhargav&#039;s IT Playground","isPartOf":{"@id":"https:\/\/bhargavs.com\/#website"},"datePublished":"2010-07-29T04:27:30+00:00","breadcrumb":{"@id":"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/bhargavs.com\/index.php\/2010\/07\/28\/how-to-convert-a-word-document-to-other-formats-using-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bhargavs.com\/"},{"@type":"ListItem","position":2,"name":"How to convert a word document to other formats using PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/bhargavs.com\/#website","url":"https:\/\/bhargavs.com\/","name":"Bhargav's IT Playground","description":"Passion for Technology. Power of Collaboration.","publisher":{"@id":"https:\/\/bhargavs.com\/#\/schema\/person\/28f6d8c9b29f3a879483d65fc2ab5e26"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bhargavs.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/bhargavs.com\/#\/schema\/person\/28f6d8c9b29f3a879483d65fc2ab5e26","name":"Bhargav","logo":{"@id":"https:\/\/bhargavs.com\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/bhargavs.com"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1647,"url":"https:\/\/bhargavs.com\/index.php\/2010\/03\/16\/send-a-tweet-from-powershell\/","url_meta":{"origin":1653,"position":0},"title":"Send a Tweet from PowerShell","author":"Bhargav","date":"March 16, 2010","format":false,"excerpt":"While I chose to keep this article here for archiving, Please note that this doesn't work anymore. Twitter API has since changed and what used to work, doesn't anymore. I was reading Shay\u2019s article on how to send direct messages on twitter using PowerShell when I couldn\u2019t resist but find\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/bhargavs.com\/index.php\/category\/microsoft\/powershell\/"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/www.bhargavs.com\/wp-content\/uploads\/2010\/03\/image-thumb.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.bhargavs.com\/wp-content\/uploads\/2010\/03\/image-thumb.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.bhargavs.com\/wp-content\/uploads\/2010\/03\/image-thumb.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1650,"url":"https:\/\/bhargavs.com\/index.php\/2010\/03\/29\/script-to-enable-preview-pane-for-powershell-scripts\/","url_meta":{"origin":1653,"position":1},"title":"Script to enable preview pane for PowerShell scripts","author":"Bhargav","date":"March 29, 2010","format":false,"excerpt":"If you are running Windows 7, you probably know what preview pane is. And if you use PowerShell and create ps1 scripts, you may also wonder how can you enable preview for PowerShell scripts in Windows Explorer. Well, Nate Bruneau shared how to edit registry to enable preview for ps1\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/bhargavs.com\/index.php\/category\/microsoft\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":34526,"url":"https:\/\/bhargavs.com\/index.php\/2024\/01\/30\/clearing-microsoft-teams-cache-with-powershell\/","url_meta":{"origin":1653,"position":2},"title":"Clearing Microsoft Teams Cache with PowerShell","author":"Bhargav","date":"January 30, 2024","format":false,"excerpt":"Introduction I recently came across a need to clear Teams cache. While the task might be simple, I ended up spending a little more time to address the scenarios I can foresee so the PowerShell script is more useful that a single use case. In this blog post, we'll be\u2026","rel":"","context":"In &quot;General&quot;","block_context":{"text":"General","link":"https:\/\/bhargavs.com\/index.php\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1658,"url":"https:\/\/bhargavs.com\/index.php\/2010\/12\/09\/powershell-script-to-report-uptime\/","url_meta":{"origin":1653,"position":3},"title":"PowerShell script to report uptime","author":"Bhargav","date":"December 9, 2010","format":false,"excerpt":"UPDATED - Fixed issues reporting boottime. 3\/20\/2012 I was reading Hey, Scripting Guy! article \u201cCalculating Server Uptime\u201d and decided to write a script that can do the same. While the article has very nice script that calculates uptime from event log, my script isn\u2019t fancy and simply calculates uptime since\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/bhargavs.com\/index.php\/category\/microsoft\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1203,"url":"https:\/\/bhargavs.com\/index.php\/2015\/12\/23\/how-to-find-net-framework-version-using-powershell\/","url_meta":{"origin":1653,"position":4},"title":"How to find .NET Framework version using PowerShell","author":"Bhargav","date":"December 23, 2015","format":false,"excerpt":"Often times when I am getting ready to install Exchange 2016 or Exchange 2013, I look at pre-requisites and wonder if correct version of .NET Framework is already installed on the server or not. It certainly saves me time if it is already installed and depending on status of latest\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/bhargavs.com\/index.php\/category\/microsoft\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1670,"url":"https:\/\/bhargavs.com\/index.php\/2011\/08\/22\/microsoft-exchange-2010-powershell-cookbook-review\/","url_meta":{"origin":1653,"position":5},"title":"Microsoft Exchange 2010 PowerShell Cookbook Review","author":"Bhargav","date":"August 22, 2011","format":false,"excerpt":"Disclaimer: I am not paid to write about this book and the review written here is my own view. I was recently contacted by Packt Publishing about their recently published book \u201cMicrosoft Exchange 2010 PowerShell Cookbook\u201d. I have voluntarily reviewed books in the past (i.e. Windows Server 2003 Security: A\u2026","rel":"","context":"In &quot;Exchange 2010&quot;","block_context":{"text":"Exchange 2010","link":"https:\/\/bhargavs.com\/index.php\/category\/microsoft\/exchange-server\/exchange-2010\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_shortlink":"https:\/\/wp.me\/pkROc-qF","_links":{"self":[{"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/posts\/1653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/comments?post=1653"}],"version-history":[{"count":0,"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/posts\/1653\/revisions"}],"wp:attachment":[{"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/media?parent=1653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/categories?post=1653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bhargavs.com\/index.php\/wp-json\/wp\/v2\/tags?post=1653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}