-3
#Progress bar script of PowerShell to download Kubescape
$fullurl='https://github.com/kubescape/kubescape/releases/download/v2.0.168/kubescape-windows-latest'
$Total_size=((Invoke-WebRequest -Uri $fullurl -Method Head).Headers).'Content-Length'
$Downloaded_size=0
while($Downloaded_size -lt $Total_size){
$downloaded_percentage= ((100/$Total_size)*$Downloaded_size)+1
[MATH]::Floor($downloaded_percentage)
$Downloaded_size += ?
}

here is how to fetch real-time downloaded size during the downloading process without using any buffer operation.

  • In the code you provided you haven't even started downloading the file yet. There's nothing to monitor. – Jesse Aug 31 '22 at 17:46

1 Answers1

0

As per Jesse's download comment and my $Total_size comment, your refactor could be this:

$fullurl    = 'https://github.com/kubescape/kubescape/releases/download/v2.0.168/kubescape-windows-latest'
$Total_size = ((Invoke-WebRequest -Uri $fullurl -Method Head).Headers).'Content-Length'
Invoke-WebRequest $fullurl -OutFile "$env:USERPROFILE\Downloads\kubescape-windows-latest"

The above will of course auto-show a progress bar in the console/ISE/VSCode.

postanote
  • 15,138
  • 2
  • 14
  • 25