Displaying Progress from External Programs in PowerShell

Unfortunately, it is often necessary to call external programs from PowerShell. Whenever this is done, the controlling code needs to process output and errors. Some of those tools implement long running tasks which do not provide any progress information. This post presents a code to intercept progress messages from standard output to display progress from external programs.

Due to the fact that external programs cannot directly offer control information to PowerShell, it is necessary to parse the output for data and errors. Sometimes a long running task is easier to monitor if progress information is provided.

My cmdlet called ConvertTo-Progress intercepts progress from external programs by looking for special keywords. The following code demonstrates how this is done:

& MyLongRunningTask.exe | ConvertTo-Progress

In the above example MyLongRunningTask.exe needs to generate message of the following format:

Activity="Important task" Status="Subtask" Percentage=0
Activity="Important task" Status="Subtask" Percentage=83
Activity="Important task" Status="Subtask" Percentage=100

The message may contain any of the following keywords which are easily recognized as parameters for Write-Progress:

The following code implements the cmdlet ConvertTo-Progress:

In case you have any feedback please use the comments below or create a new revision on GitHub.

Feedback is always welcome! If you'd like to get in touch with me concerning the contents of this article, please use Twitter.