Progress indication for a script block

In my previous post i showed you how to run a powershell script block in the background. While this block runs in the background it would be great to indicate that the background process is still running and the script is waiting for the background process to finish. Isn’t it frustrating you when you just look at a powershell window running a script without being sure that the script is not frozen?

Well at least just indicate that the script is still doing its job 🙂

In my example i start a process doing some intersting calculations in the background

Enable-PSRemoting -Force | Out-Null
$s = new-pssession -computername '.' -Name 'BackGround' -Credential $Credential
$Job = Invoke-Command -Session $s -AsJob -ArgumentList $Arguments -ScriptBlock `
Param (
#Have some very useful arguments...
#Do some intresting calculations taking lots of time
Start-Sleep -s 6000
$tick = '|'
While (($Job.state -ne 'Completed') -and ($Job.state -ne 'Failed'))
Switch ($tick){
'\' {$tick = '|'}
'|' {$tick = '/'}
'/' {$tick = '-'}
'-' {$tick = '\'}
Write-Host -ForegroundColor White `r 'Calculating! Do not disturbe!  ' $tick -NoNewline
Start-Sleep -Milliseconds 500
$tick = "DONE"
Write-Host -ForegroundColor Green `r 'Calculating! Do not disturbe!  ' $tick -NoNewline

So, now you have a gyratory rod indicating that a background script is still running.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s