Problem using powershell to push zip file to Octopus

I’m setting up Continua as a build server with Octopus Deploy for deployments. The final stage of the build process is to run a powershell script to push the 7z file containing the build artefacts to Octopus. So I’m using this script -

$wc = new-object System.Net.WebClient
$wc.UploadFile("http://localhost/octopus/api/packages/raw?apiKey=API-### ", $source)

But I’m getting the following error:-
Exception calling “UploadFile” with “2” argument(s): "The remote server returned an error: (400) Bad Request."
At line:1 char:15

Any help gratefully received.

Hi Ian,

Thanks for reaching out. The error 400 means you are trying to push a package that already exists in the repository. What the repository checks to see if the package exists or not is the ID and the version. If there’s already a package with that ID + Version combination, regardless of their content, they will count as duplicates.

You can add ?replace=true at the end of the URL to override the current package in the repository with the new one. Keep in mind that this feature was introduced in Octopus 3.2.4. In your case your URL should be


May I ask why are you using the Powershell approach to push the package? We only recommend that in specific cases where users cant use Nuget.exe or Octo.exe to do the push. I’d recommend you to use those as they involve a lot less code. If you’re gonna keep pushing package from that same server over and over, you’ll just have to drop one of those executables in the server once.



Hope that helps,

Hi Dalmiro

Thanks for your help, I have it all working now. I understand that the filename needed to contain version numbers etc. in order successfully upload (the 400 error wasn’t very informative).

The reason that I used the Powershell approach was because when I went to the Packages page of the Octopus Web Portal (octopus/app#/library/packages), it talks about either using nuget or Powershell. I didn’t know about Octo.exe. Octo is much much easier.

Ian Bate

Glad I could help!