I am trying to get a C# Form that is tied to a log file to display the contents of a Powershell script that is sending Write-Output data as the script performs tasks.
The problem is that the form remains blank until the Powershell script completes, then updates the richtext box all at once. We need it to update stepwise while the script is running.
We start the transcription like this:
$LogContent = Get-Content "$ConfigurationFile"
Start-Transcript -Path $LogContent.LogPathname
The script has several sections and each time it moves from one part to the next we do:
Write-Output "Now starting Phase I - Data Prep"
# (Do Powershell stuff related to Phase I)
Write-Output "Phase I - Step A"
# (Do Powershell stuff related to Step A)
Write-Output "Phase I - Step B"
# (Do Powershell stuff related to Step B)
Write-Output "Phase I - Step C"
# (Do Powershell stuff related to Step C)
Write-Output "Phase I Data Prep complete. Moving to Phase II"
# (Do some pre-Phase II stuff in Powershell)
Write-Output "Starting Phase II - Data Projection"
# (etc)
Write-Output "Process Complete - Please proceed with next step"
Stop-Transcript
All of the variables are correct, the log files are written correctly. The only thing not working as needed is the C# Windows Form RichText field updating when each Write-Output is executed.
It seems as though the the Start-Transcript is writing the stream but not actually committing it to the file until the Stop-Transcript is being called. Is this true? How can I get the Write-Outputs to display on the C# Form as they are called in Powershell?
EDIT: The Powershell console window is being invoked with:
ProcessWindowStyle.Hidden