Skip to content

Instantly share code, notes, and snippets.

@eugrus
Created February 27, 2026 16:26
Show Gist options
  • Select an option

  • Save eugrus/68840fdbcdc546aa1bd3a91e3d5365fb to your computer and use it in GitHub Desktop.

Select an option

Save eugrus/68840fdbcdc546aa1bd3a91e3d5365fb to your computer and use it in GitHub Desktop.
Convert all RTFs from a folder to DOCX using MS Word
$folder = "."
$word = New-Object -ComObject Word.Application
$word.Visible = $false
# 6 = wdFormatXMLDocument (DOCX)
$saveFormat = 12
Get-ChildItem -Path $folder -Filter *.rtf | ForEach-Object {
$rtfPath = $_.FullName
$docxPath = [System.IO.Path]::ChangeExtension($rtfPath, ".docx")
$doc = $word.Documents.Open($rtfPath, $false, $true)
$doc.SaveAs([ref]$docxPath, [ref]$saveFormat)
$doc.Close()
}
$word.Quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment