$desktop = [Environment]::GetFolderPath("Desktop")
|
$doc = Get-ChildItem -LiteralPath $desktop -Filter "*.docx" |
|
Where-Object { $_.Name -like "*docx" -and $_.Name.Length -gt 10 } |
|
Sort-Object LastWriteTime -Descending |
|
Select-Object -First 1 -ExpandProperty FullName
|
if (-not $doc) {
|
throw "No docx file found on Desktop."
|
}
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
$zip = [IO.Compression.ZipFile]::OpenRead($doc)
|
try {
|
$entry = $zip.GetEntry("word/document.xml")
|
$reader = [IO.StreamReader]::new($entry.Open())
|
try {
|
$xml = $reader.ReadToEnd()
|
} finally {
|
$reader.Close()
|
}
|
} finally {
|
$zip.Dispose()
|
}
|
$xml = $xml -replace '</w:p>', "`n"
|
$xml = $xml -replace '<[^>]+>', ''
|
[System.Net.WebUtility]::HtmlDecode($xml)
|