Uploading file to HTTP via Powershell Uploading file to HTTP via Powershell powershell powershell

Uploading file to HTTP via Powershell


A year late, so you probably don't need the answer anymore, but what worked for me was:

Invoke-RestMethod -Uri $uri -Method Post -InFile $uploadPath -UseDefaultCredentials

Mine needed to use windows auth as the currently logged in user... From this other answer, looks like you can use -cred in some cases and have to build out an Authorization header in others.


Even later post but these Invoke-RestMethod solutions (and a few others) didn't work for me. My service endpoint was failing with missing boundaries and other "content" issues, depending on my trial and error.

I tried using WebClient's Uploadfile() functionality and it worked for me.Thankfully, it's concise.

$wc = New-Object System.Net.WebClient$resp = $wc.UploadFile($uri,$uploadPath)