title: Basic Powershell - batch convert Word Docx to PDF
body: <p>I am trying to use PowerShell to do a batch conversion of Word Docx to PDF - using a script found on this site:
  <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2013/03/24/weekend-scripter-convert-word-documents-to-pdf-files-with-powershell.aspx" rel="noreferrer">http://blogs.technet.com/b/heyscriptingguy/archive/2013/03/24/weekend-scripter-convert-word-documents-to-pdf-files-with-powershell.aspx</a></p>
  
  <pre><code># Acquire a list of DOCX files in a folder
  $Files=GET-CHILDITEM "C:\docx2pdf\*.DOCX"
  $Word=NEW-OBJECT –COMOBJECT WORD.APPLICATION
  
  Foreach ($File in $Files) {
      # open a Word document, filename from the directory
      $Doc=$Word.Documents.Open($File.fullname)
  
      # Swap out DOCX with PDF in the Filename
      $Name=($Doc.Fullname).replace("docx","pdf")
  
      # Save this File as a PDF in Word 2010/2013
      $Doc.saveas([ref] $Name, [ref] 17)  
      $Doc.close()
  }
  </code></pre>
  
  <p>And I keep on getting this error and can't figure out why:</p>
  
  <pre><code>PS C:\docx2pdf&gt; .\docx2pdf.ps1
  Exception calling "SaveAs" with "16" argument(s): "Command failed"
  At C:\docx2pdf\docx2pdf.ps1:13 char:13
  +     $Doc.saveas &lt;&lt;&lt;&lt; ([ref] $Name, [ref] 17)
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : DotNetMethodException
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Also - how would I need to change it to also convert doc (not docX) files, as well as use the local files (files in same location as the script location)?</p>
  
  <p>Sorry - never done PowerShell scripting...</p>