Tables.
A Script run from PowerShell command can be used to convert the file format from text to many other MS types
Reading Material
https://learn-powershell.net
http://ss64.com/ps/
A PowerShell script is the equivalent of a Windows CMD or MS-DOS batch file, the file should be saved with a .ps1 extension.
An important find for me, is that in Command Line you can use %USERPROFILE% to get to your home directory this doesn't work for PowerShell.
In PowerShell the direct comparison is $ENV:UserProfile .
To link to home directory you can use $home or the even simpler tilde (~)
Example of this is the following PowerShell script,
This script looks in the origin folder and converts
any file with the extension .doc or docx etc to pdf. this effectively uses PowerShell to open word
converts the documents and save them back as a pdf.
$origin = '~\Documents\doc2pdf'
$destination = '~\Documents\doc2pdf'
$word_app = New-Object -ComObject Word.Application
echo "Seeking changes in the source folders..."
Get-ChildItem -Path $origin -Filter *.doc? | ForEach-Object {
if (-Not (Test-Path "$destination\$($_.BaseName).pdf")) {
$document = $word_app.Documents.Open($_.FullName)
$pdf_filename = "$destination\$($_.BaseName).pdf"
echo "$($_.FullName) converted $pdf_filename!"
$document.SaveAs([ref] $pdf_filename, [ref] 17)
$document.Close()
}
}
$word_app.Quit()
We can combine PowerShell in command line that is called from task scheduler.
In this example I open PowerShell and search the folder for a text string, returning matching files with the relevant lines all formatted in a table.
NOTE this will need to be saved with .cmd extension to work
@PowerShell -ExecutionPolicy Bypass -noexit -Command Invoke-Expression $('$args=@(^&{$args} %*);'+[String]::Join(';',(Get-Content '%~f0') -notmatch '^^@powershell.*EOF$')) & goto :EOF
gci -path '$home\Documents\doc2pdf\' -filter '*' | Select-String -patt "34444" | select Filename, LineNumber | Format-Table -a
Jump Back to PowerShell and me on....