This is my first question on SO so here goes!
I'm getting started with a simple powershell script that I intend to use to benchmark some archiving software. I want to run the archiver (7-zip on Windows 10 in this case) and write the console output to a text file to keep as a log. Then, I want to append to that same log the start time, end time, file sizes... etc.
The problem is I'm having difficulty sending the output to the text file. During multiple tries I never could make it work. I tried Out-File and also the normal ">" redirect but it still ends empty. I even tried setting -PassThru parameter on Start-Process but it only sent the object properties instead of the Host contents.
Curiously, when I make this command run in CMD with the ">" redirect, it works as expected and I find a text file with the expected contents.
This is my current powershell script:
$7zFilePath = "C:\Program Files\7-Zip\7z.exe"
$dateStart = Get-Date
$contentsToArchive = "D:\Temp -Local\Attack on Titan- Before the Fall-002.jpg"
$workingFolder = "D:\Temp"
$archiveName = "testing {0:yyyy-MM-dd hh.mm.ss.ffff}" -f ($dateStart)
$argument = "a -t7z -m0=LZMA2 -mmt=on -mx9 -md=64m -ms=16g -mfb=273 -mqs=on -mtc=on -mta=on -bb3 `"$workingFolder\$archiveName.7z`" `"$contentsToArchive`""
Set-Location $workingFolder
Start-Process -FilePath $7zFilePath -NoNewWindow -ArgumentList $argument | Out-File ".\$archiveName.txt"