I have code that creates a Process, starts it, and then, I want to view the progress. The process executes DTExec.exe, which runs SQL Server SSIS packages. In my case, a log table gets updated as each file is imported into a table. Thus, with the following code which combines the write-progress with a SQL query, I should be able to monitor progress. If I start my full script, and run the following code (with the supporting code to execute the SQL code and resolve variables) in either a Windows Powershell window or the Powershell ISE, I see the progress bar, but it does not display in the fully executing code. The full code basically does some up-front maintenance, creates a new System.Diagnostics.ProcessStartInfo object, populates it, creates a new System.Diagnostics.Process object, populates StartInfo, and starts the process. I then go into the code that should display the progress bar. I have attached the full code (which can’t actually be run without some additional data, but this is the progress bar code from it.
$tableCount = 0
$query = "SELECT COUNT(*) AS [Count] FROM dbo.ExtractLog WHERE ExtractDate >= '" + $Start + "' AND TableName NOT IN ('Start WV Extract', 'End WV Extract')"
for ($i = 0; $i -le 42; $i = $tableCount)
{
$ctr++
if (-not (Get-Process -Name DTExec -ErrorAction SilentlyContinue))
{
write-progress -activity "Import in Progress" -completed
break
}
if ($ctr % 8 -eq 0)
{
$result = Invoke-sqlcmd -serverinstance $FQDN -Database $SOURCE -Query "$query" -QueryTimeout 65535 -ConnectionTimeout 65535
$tableCount = $result.Count
$percent = ($tableCount / 42) * 100
write-progress -activity "Import in Progress" -status "$percent% Complete:" -percentcomplete $percent;
}
Start-Sleep -m 250
}