PowerShell

PowerShell 7: Changing the Style of the Progress Bar with $PSStyle

If you include a progress bar in PowerShell, you will notice that it looks different in PowerShell 5 and PowerShell 7. This is exactly the problem we will tackle in this blog post and I will show how to use $PSStyle to customize the Progress Bar. Let’s get started.

Starting Point

Here is an example to show you the issue. The script below will be executed first with PowerShell 5 and then with PowerShell 7.

$numbers = 1..99
$count = $numbers.count
foreach ($n in $numbers) {
    "Computer0$n"
    Write-Progress -Activity 'Enumerate Computers' `
    -CurrentOperation Computer0$n `
    -Status "$(([math]::Round((($n)/$count * 100),0))) %"
    Start-Sleep -Seconds 1
 }

PowerShell 5.1:

PowerShell 7:

The look is definitely different.

Changing the Style

How can we change the Style in PowerShell 5.1 or 7? The solution is $PSStyle.

Note that the variable exists only in PowerShell 7. Here is the default setting in PowerShell 7 and how to change it to the style of PowerShell 5.1.

$PSStyle.Progress.View = 'Classic'

Now the Progress Bar looks exactly the same as in PowerShell 5.1.

Categories: PowerShell

Tagged as: ,

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.