Files

16 lines
636 B
PowerShell

$Path = "C:\Temp\"
$Word_App = New-Object -ComObject Word.Application
$Format = [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatXMLDocument
$List = Get-ChildItem -Path $Path -Recurse -File -Filter '*.doc' | Where-Object { $_.Name -match '.+\.doc$' }
Foreach ($Item in $List) {
if ($Item.Name -match '.+.doc$') {
$Document = $Word_App.Documents.Open($Item.FullName)
$Docx_Filename = "$($Item.DirectoryName)\$($Item.BaseName).docx"
$Document.SaveAs([ref]$docx_filename, [ref]$Format)
$Document.Close()
#Remove-Item -Path $Item.FullName -Force
}
}
$word_app.Quit()