title: Powershell script to convert a word table to text
body: <p>I have this script that is supposed to convert the first table from a word document to text, but unfortunately it does nothing:</p>
  
  <pre><code>$word = New-Object -ComObject word.application
  $word.visible = $false
  $folderpath = "C:\mypath\myfile.docx"
  $Doc = $word.Documents.open($folderpath)
  $Doc.Tables.item(1).ConvertToText
  $Doc.saveas([ref]$folderpath, [ref]$SaveFormat::wdFormatDocumentDefault)
  $Doc.close()
  $word.Quit()
  [System.Runtime.Interopservices.Marshal]::ReleaseComObject($word)
  </code></pre>
  
  <p>However using a VB script with essentially the same code does do this seemingly easy task perfectly:</p>
  
  <pre><code>Dim wrdApp: Set wrdApp = WScript.CreateObject(""Word.Application"")
  Dim wrdDoc
  Set wrdDoc = wrdApp.Documents.Open("C:\mypath\myfile.docx")
  wrdDoc.Tables(1).ConvertToText
  wrdDoc.SaveAS ("C:\mypath\myfile.docx")
  wrdDoc.Close SaveChanges=True
  wrdApp.Quit
  Set wrdApp = Nothing
  Set wrdDoc = Nothing
  </code></pre>
  
  <p>Can anyone point me towards the reason the powershell script is simply not converting the table?</p>
  
  <p>Thank you!
  Tiaan</p>