Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsxdalv/69023c0e38f127a96b759f5453509e82 to your computer and use it in GitHub Desktop.
Save rsxdalv/69023c0e38f127a96b759f5453509e82 to your computer and use it in GitHub Desktop.
# Extended from https://superuser.com/a/1187598
$Word = New-Object -ComObject Word.Application
$Files = Get-ChildItem ".\**\*.docx"
ForEach ($File In $Files) {
$Document = $Word.Documents.Open($File.FullName)
$Name = ($Document.FullName).Replace("docx", "txt")
$def = [Type]::Missing
# 17 - pdf
# 2 - text
# 7 - unicode text
$Document.SaveAs(
#ref Object FileName,
[ref] $Name,
#ref Object FileFormat,
[ref] 7,
#ref Object LockComments,
$def,
#ref Object Password,
$def,
#ref Object AddToRecentFiles,
$def,
#ref Object WritePassword,
$def,
#ref Object ReadOnlyRecommended,
$def,
#ref Object EmbedTrueTypeFonts,
$def,
#ref Object SaveNativePictureFormat,
$def,
#ref Object SaveFormsData,
$def,
#ref Object SaveAsAOCELetter,
$def,
#ref Object Encoding,
65001
#ref Object InsertLineBreaks,
#ref Object AllowSubstitutions,
#ref Object LineEnding,
#ref Object AddBiDiMarks
)
$Document.Close()
}
$Word.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment