PowerShell display question

RojBlake

Ars Legatus Legionis
48,129
Subscriptor
I'm writing a script to keep track of a NetApp volume move job. For each volume, I'm writing stuff to the screen like:
Code:
5/10/2019 9:15:36 AM - Volume: vol_backups
5/10/2019 9:15:36 AM - Starting move...
Once the move has complete, the next displayed line is something like:
Code:
5/10/2019 11:01:20 AM - Move complete in 6419 sec.
It repeats like that for each volume.

What I'd like to do is have a line after the "Starting move..." line that says "Progress:" followed by a continuously updating progress percentage.

This is where I'm stumped. Sure, I can get the percentage and write it to the screen periodically, but then I'll end up with something ugly, like this:
Code:
5/10/2019 9:15:36 AM - Volume: vol_backups
5/10/2019 9:15:36 AM - Starting move...
Progress: 1%
Progress: 9%
Progress: 17%
Progress: 28%
Progress: 36%
[etc.]
What I want is just one "Progress:" line that I can overwrite with the current percentage.

So basically, the general question is: is it possible to do a "Write-Host" (or some other command) that overwrites the same line on the screen?

EDIT: This in the PowerShell ISE, specifically, btw.
 

RojBlake

Ars Legatus Legionis
48,129
Subscriptor
Yeah, I found the suggestion with `b and `r plus -NoNewLine right after I posted; that's what prompted me to edit the post and specify the ISE. ;) It's frustrating that it works in one environment and not the other.

Also, I'm familiar with Write-Progress, but that overlays a progress bar at the top. I'm talking about being able to overwrite screen data in the regular output location.

It's not a huge deal if it's not doable - I'll go with Write-Progress if not.
 

Lt_Storm

Ars Tribunus Angusticlavius
21,343
Subscriptor++
Yeah, I found the suggestion with `b and `r plus -NoNewLine right after I posted; that's what prompted me to edit the post and specify the ISE. ;) It's frustrating that it works in one environment and not the other.

Also, I'm familiar with Write-Progress, but that overlays a progress bar at the top. I'm talking about being able to overwrite screen data in the regular output location.

It's not a huge deal if it's not doable - I'll go with Write-Progress if not.

It looks like ISE doesn't have a good enough console implementation to rewrite a console line (ISE's console implementation is apparently far worse than Windows' ever was; it might look like a console, but a console it is not). If you wanted to do something like that, you would likely have to integrate with it's graphics component and display a widget over the top like Write-Progress does. Suffice it to say: that isn't simple.

Either go with Write-Progress, write out 100 lines to the 'console', or use a real terminal (VSCode has a good one, and Microsoft is investing in real terminals).