Skip to content

Instantly share code, notes, and snippets.

@ShortArrow
Last active July 8, 2025 05:50
Show Gist options
  • Save ShortArrow/c682281d0e0a5a80746106fd6fb6831c to your computer and use it in GitHub Desktop.
Save ShortArrow/c682281d0e0a5a80746106fd6fb6831c to your computer and use it in GitHub Desktop.
How to translate *.doc to *.docx, this is need Microsoft Word

Usage

pwsh -c "./doc2docx.ps1 -FolderPath ./target -Verbose"

Content of doc2docx.ps1

param(
  $FolderPath = "C:\Path\To\Your\Files",
  [switch]$Verbose = $false
)

$FolderPath = Resolve-Path $FolderPath

$Word = New-Object -ComObject Word.Application
$Word.Visible = $false

$files = Get-ChildItem $folderPath -Filter *.doc
foreach ($file in $files) {
  if ($Verbose) {
    Write-Host "Processing file: $($file.FullName)"
  }
  $Doc = $Word.Documents.Open($file.FullName)
  $Doc.SaveAs([ref] $file.FullName.Replace('.doc', '.docx'), [ref] 16)
  $Doc.Close()
}

$Word.Quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment