I have a PowerShell script to convert a local vmware instance to a remote AWS instance. Two steps in this process are calls to external CLI programs that have their own progress bars. The problem is they're not being displayed properly.
When run by itself, vmware-vdiskmanager displays the following line, with the percentage number updating as each point is completed. When called in PowerShell, I get a new line every time the percentage point is updated, with the whole text repeated.
Convert: 0% done.
Another step is ec2-import-instance which has a slightly fancier progress bar. When run by itself, it fills the space and updates the percentage. From PowerShell, it never updates. It just displays as below static until the job is finished.
0% |--------------------------------------------------| 100%
Both commands in my PowerShell script have their output piped to Out-Host. I don't understand how PowerShell interacts with the output of programs. I never had problems like this in batch, but there are a few steps in this process where I need the power of a real programming language.
Any idea what's going on or how to make it display like they do when run by themselves?
Edit: As an example, here's the command for the first one.
vmware-vdiskmanager -r $filename -t 5 stream.vmdk | Out-Host
There's obviously logic earlier defining $filename. It does the conversion just fine, I just get 101 lines of output.
Creating disk 'stream.vmdk'
Convert: 0% done.
Convert: 1% done.
Convert: 2% done.
Convert: 3% done.
Convert: 4% done.
Convert: 5% done.
Convert: 6% done.
Convert: 7% done.
Convert: 8% done.
Convert: 9% done.
Convert: 10% done.
Convert: 11% done.
Convert: 12% done.
The second example just doesn't update the output. It has more parameters and references some environment variables. This is all I see for output.
Uploading the manifest file
Uploading 19979618816 bytes across 1906 parts
0% |--------------------------------------------------| 100%
|===================================================|
Done
Average speed was 1.378 MBps
My best guess was something like PowerShell doesn't support printing backspace characters or positioning output of external executables, that Out-Host is a unidirectional stream. The difference in two behaviors could be a matter of flushing output in the external program itself. I'm just guessing here.