0
votes

I'm using PowerShell to automate my build and upload process. As part of it, I'm using Invoke-RestMethod to upload my file to my API endpoint. This is my command to upload:

Invoke-RestMethod -Uri $uploadEndpoint -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines -Headers $headers | Out-Null

Before invoking this command I'm using Write-Host a line without breaking to a new line, and when it's done I'm using Write-Host with a line break with "OK", so the output is something like this:

Uploading version to server... [OK]

What I'm wondering is if there is a way to get the progress of the file upload from the Invoke-RestMethod and while uploading show the progress percentage of the call. Something like:

Uploading version to server... 43%
1
This is what the Write-Progress cmdlet is for. [Get-help -Name Write-Progress -Full] You must provide the data to calculate how ti will count. What did you search for? What have you tried? What happened when you did? Post your code? Provide MRE --- How to ask --- Don't ask --- Proper Topic - postanote
Even though Write-Progress is made for this type of behaviour, I am not aware Invoke-RestMethod provides information with which one could calculate the progress. - Alex_P

1 Answers

0
votes

Theare are 2 way that I know

  1. Write-Progress -Activity "Uploading version to server..." -PercentComplete $perc
  2. Write-host "`r"Uploading version to server... $perc" -NoNewline

The first method generate a graphical loading bar, the second one is a simple line of text and is more like what you are looking for.