I have a PowerShell script that needs to kick off a batch file and essentially monitor its progress. My assumption was that I could use Start-Process without -wait and this would allow me to do some processing immediately after kicking off the batch file. I'm currently testing a simple script as below:
$BatchFilePath = D:\Scripts\testDB.bat
$stamp = (Get-Date).ToString("yyyyMMdd.hh.mm.ss")
Start-Process -FilePath $BatchFilePath -PassThru -WindowStyle Hidden -RedirectStandardOutput D:\Scripts\DBBackupOutput_${stamp}.log
do
{
$JobOutputFile = Get-Content D:\Scripts\DBBackupOutput_${stamp}.log
$LineCount = $JobOutputFile.count
Write-Host 'Line count: ' $LineCount
Start-Sleep -s 5
} until ($LineCount -gt 1)
Once the batch file has been started I was trying to monitor the output in the log file but it isn't working as expected. The script seems to pause once the batch file is executed but I was expecting to see a line count every 5 seconds.
Is my understanding here correct? Or should I be using a Job instead? Or is something like this even possible?
Thanks in advance