View difference between Paste ID: U7xgs8mM and
SHOW: | | - or go back to the newest paste.
1-
1+
# Acquire a list of DOCX files in a folder
2
3
$File=”C:\Foofolder\foofile.docx"
4
$Files=GET-CHILDITEM ‘C:\FooFolder\*.DOCX’
5
$Word=NEW-OBJECT –COMOBJECT WORD.APPLICATION
6
 
7
8
Foreach ($File in $Files) {
9
10
    # open a Word document, filename from the directory
11
12
    $Doc=$Word.Documents.Open($File.fullname)
13
14
 
15
16
    # Swap out DOCX with PDF in the Filename
17
18
$Name=($Doc.Fullname).replace(“docx”,”pdf”)
19
20
 
21
22
    # Save this File as a PDF in Word 2010/2013
23
24
    $Doc.saveas([ref] $Name, [ref] 17)
25
26
    $Doc.close()
27
28
}