powershell script: progress bar infinite loop, until key pressed

Ale Madama 276 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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,355 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,486 Reputation points Microsoft Vendor
    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 44,696 Reputation points
    2021-03-23T18:43:50.627+00:00

    Yes, it is. Is this a homework assignment?

    1 person found this answer helpful.