Should you embody a progress bar in PowerShell, you’ll discover that it seems totally different in PowerShell 5 and PowerShell 7. That is precisely the issue we’ll sort out on this weblog publish and I’ll present the best way to use $PSStyle to customise the Progress Bar. Let’s get began.
Beginning Level
Right here is an instance to indicate you the difficulty. The script beneath will likely be executed first with PowerShell 5 after which with PowerShell 7.
$numbers = 1..99
$rely = $numbers.rely
foreach ($n in $numbers) {
"Computer0$n"
Write-Progress -Exercise 'Enumerate Computer systems' `
-CurrentOperation Computer0$n `
-Standing "$(([math]::Spherical((($n)/$rely * 100),0))) %"
Begin-Sleep -Seconds 1
}
PowerShell 5.1:
PowerShell 7:
The look is unquestionably totally different.
Altering the Model
How can we alter the Model in PowerShell 5.1 or 7? The answer is $PSStyle.
Observe that the variable exists solely in PowerShell 7. Right here is the default setting in PowerShell 7 and the best way to change it to the fashion of PowerShell 5.1.
$PSStyle.Progress.View = 'Basic'
Now the Progress Bar seems precisely the identical as in PowerShell 5.1.
Printed by