Last active
August 10, 2021 14:08
-
-
Save LudovicOmarini/84210f6a9fe1847b681c0e7d3d392546 to your computer and use it in GitHub Desktop.
This script run word application silently to convert ".doc" files to ".docx" files, include to not show the SaveAs dialog window. It's work recursively to convert all availables files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Convert ".doc" files to ".docx" files recursively. | |
.DESCRIPTION | |
This script run word application silently to convert ".doc" files to ".docx" files, include to not show the SaveAs dialog window. | |
It's work recursively to convert all availables files. | |
.EXAMPLE | |
.\Convert-Doc-To-Docx.ps1 -FolderPath 'c:\FolderWithDocFiles\' | |
#> | |
Param( | |
[Parameter(Mandatory=$true)][string]$FolderPath=$(throw "You haven't set a folder path.") | |
) | |
[ref]$SaveFormat = “microsoft.office.interop.word.WdSaveFormat” -as [type] | |
$word = New-Object -ComObject word.application | |
$word.visible = $false | |
$fileType = “*doc” | |
Get-ChildItem -path $folderpath -include $fileType -Recurse | | |
foreach-object ` | |
{ | |
$path = ($_.fullname).substring(0,($_.FullName).lastindexOf(“.”)) | |
“$path” | |
$doc = $word.documents.OpenNoRepairDialog($_.fullname) | |
$doc.saveas(([ref] $path).Value, ([ref]$SaveFormat::wdFormatDocumentDefault).Value) | |
$doc.close() | |
rm -Force -Recurse "$path.doc" | |
} | |
$word.Quit() | |
$word = $null | |
[gc]::collect() | |
[gc]::WaitForPendingFinalizers() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment