Skip to content

Instantly share code, notes, and snippets.

@eugrus
Created March 19, 2025 09:03
Show Gist options
  • Save eugrus/0f61d66170db48c64e11104703bdbadb to your computer and use it in GitHub Desktop.
Save eugrus/0f61d66170db48c64e11104703bdbadb to your computer and use it in GitHub Desktop.
param(
[string]$filePath
)
# Ensure the file exists
if (-not (Test-Path $filePath)) {
Write-Error "File does not exist: $filePath"
exit 1
}
# Resolve the full path
$filePath = Resolve-Path -Path $filePath
# Get temp file path
$tempFile = Join-Path ([System.IO.Path]::GetTempPath()) "$(Split-Path -Leaf $filePath).txt"
# Create a new Word Application COM object
$word = New-Object -ComObject Word.Application
$word.Visible = $false
# Open the document
$document = $word.Documents.Open($filePath)
# Read the content
$content = $document.Content.Text
# Close the document without saving
$document.Close([ref]$false)
# Save content to a temp file
$content | Set-Content -Path $tempFile -Encoding UTF8
# Open the temp file in Notepad++
Start-Process -FilePath "notepad++.exe" -ArgumentList "`"$tempFile`""
# Quit Word
$word.Quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment