powershell script: progress bar infinite loop, until key pressed

Ale Madama 291 Reputation points
2021-03-23T09:59:50.113+00:00

Hi all,
I would have to create a script (powershell or DOS) doing this:

a wording printed (e.g. "debug in progress:") and beside a progress bar (dots increasing....)
when the dots reach number of 100, they start from 1 dot (still beside the same wording):

debug in progress:...........................

this in an infinite loop, until I press a key

is it possible?
thanks!

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2021-03-24T06:11:54.287+00:00

    Hi,

    You can try something like this.

    $notpressed = $true  
    $string = 'debug in progress:'  
    $dots = 100  
    $i = 0  
    while($notpressed){  
        $i++  
        if([console]::KeyAvailable)  
        {  
            $notpressed = $false      
        }      
        else{  
            if($i%($dots+1) -eq 1)  
            {  
                Write-Host $string -NoNewline  
                Start-Sleep -Milliseconds 500            
            }  
            elseif($i%($dots+1) -eq 0)  
            {  
                Write-Host '.'  
                Start-Sleep -Milliseconds 500             
            }  
            else{  
                Write-Host '.' -NoNewline  
                Start-Sleep -Milliseconds 500             
            }  
        }  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2021-03-23T18:43:50.627+00:00

    Yes, it is. Is this a homework assignment?

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.