Using PowerShell to issue curl script to Orthanc

I am using PowerShell in Windows 10 and have been able to use curl to issue a query and return a series of named parameters (patient name).

I want to issue a POST command on these series of named parameters so I can send all to a specific modality, but the “multiple” is tripping me up. I can issue the POST command on a single one of the parameters, but not on the entire series of them.

So I get my patient name by typing

curl.exe -u username:password http://site.url.8042/patients

That gives me a screen output, or I can output to a text file by appending > c:\directory\patients.txt

So I have the series of named parameters and if I do only one it works fine:

I don’t need quotes or brackets, which I think is what is tripping me up.

curl.exe -u username:password -X POST http://site.url:8042/modalities/MCTEST/store -d 6a3eb7c4-a9d83950-24d36e94-5c20d248-0b5ce989

So when I want to do multiples, the command I’m using within powershell is

curl.exe -u username:password -X POST http://site.url:8042/modalities/MCTEST/store -d ‘[“6a3eb7c4-a9d83950-24d36e94-5c20d248-0b5ce989”,“8c93b430-757278ab-21ab643c-c98aa03d-da14148e”,“b8f648fa-175de243-de76b1c0-2dc7551a-928b86a5”,“c865b966-f0c7d2c2-0a1114e0-80531305-31cd104e”,“aac7f73f-fcb922ef-b950c4c1-ee1d512e-e2aeb5ae”]’

I’ve tried subbing the double quotes with a backslash, tried adding a backslash, I’ve tried everything i can think of…I’m missing something.

I get a response of “must provide a json value” I’m not sure what my error is in my syntax. Any ideas?


This doesn’t seem like an Orthanc related issue but rather a need to learn how to use PowerShell.
You are not on the right forum for such a question.
The only thing we can help you with in this forum is related to the Orthanc book and from your command I understand you have already read this:

You should better check with the PowerShell community/documentation.



Hi Steve,

Due to numerous issues (including escaping, ease of use of returned data and error handling), I think that Invoke-RestMethod (standard in Powershell <= 3, I guess) is much easier to use than curl.exe and I now exclusively use it.

I haven’t tried your particular scenario, but I just tried to add a modality in my running Orthanc with the following call:

curl.exe -v -X PUT http://localhost:8042/modalities/ORTHANCC -d ‘{“AET” : “ORTHANCC”, “Host”: “”, “Port”: 2002}’

And, indeed, it doesn’t work (as can be checked with curl.exe http://localhost:8042/modalities?expand).

I haven’t tried very hard to understand why, because the following works fine:

Invoke-RestMethod -Method PUT -Uri http://localhost:8042/modalities/ORTHANCC -Body ‘{“AET” : “ORTHANCC”, “Host”: “”, “Port”: 2002}’

Unless you really insist on using curl.exe (maybe for cross-platform scenarios), you might want to give Invoke-RestMethod a try.

A very welcome bonus of Invoke-RestMethod is that the returned Json data can directly be used as native Powershell objects. For instance, the following script will download all instances in a series, as Dicom files:

$ctSeries = ‘fac4b929-f562dd71-ad235bdb-40592be7-3e181b06’
$ProgressPreference = “SilentlyContinue” # speeds up transfers by hiding the progress bar that appears in the console

$series = Invoke-RestMethod -Method GET -Uri “http://localhost:8042/series/$ctSeries

foreach($instance in $series.Instances) {
Invoke-RestMethod -Method GET -Uri “http://localhost:8042/instances/$instance/file” -OutFile “CT_$instance.dcm”

(Notice the ease of $series.Instances)

Hope this helps!


(correction: Invoke-RestMethod is available in Powershell >= 3.0, introduced in 2012)

Thanks everyone for the info.
I’m working on trying to learn the system. This application is new to me and I’m finding it pretty powerful and it’s working fairly well for what I need it to do. It’s been about 20 years since I’ve done any heavy coding, which was VB4.0 if you can believe that.
I’m on somewhat of a time crunch, so I’m trying to figure things out as I go and use the resources I have available and there’s a lot of documentation on Orthanc using Curl, so that’s what I’m running with for now until I figure out how to write some more detailed scripts and send them to Orthanc.

I appreciate the info… Thanks!

Hi Steve

I can understand why you wanna get curl.exe working instead of relying on Powershell.

However, even if we dig around and find the magic escaping sequence that would make it work, it would still require you to tweak the examples.

I think the easiest way in your case would be to enable the Windows Subsystem for Linux and then simply use bash or zsh. It just takes a few clicks to get the system going, you can choose many distros (Ubuntu is very easy to use, but others are available, too) and you’ll then be able to directly paste curl examples from the Orthanc book in your terminal.

Let us know how it goes!

Yes, I’m now running Ubuntu under Windows to issue some of my curl commands due to the limitations of the command line and powershell.
I can use the Windows command line to run a basic command send the outputs I need to text files and then I can tweak the curl command and issue more complex commands such as POST from Ubuntu.

It’s working for me for now until I have more time to figure out how to write scripts in a modern scripting format. It’s been a long time since VB4.0! Yes, I’m that old!

Thanks for your help!

Ive mentioned on a couple of posts, check out Mirth Connect as a tool for initiating Post requests against Orthanc. Very easy to control with little programming. I’ve done simple accession queries, to CSV import queries, prior fetch intiation based on body type, to even SMS an accession to retrieve a study. PM me if you had questions on how to set it up, quite simple and powerful.

Thanks for the info, Bryan. I just downloaded it and I’ll take a look and hit you up if I have any questions.

I’m using Orthanc to handle a PACS migration after a failure failure at using eFilm. Orthanc has much more customizable features and being able to send multiple (hundreds/thousands) of dicom instances in a single dicom connection is critical for what I’m doing. If Mirth can help make it more efficient, I’m all for that! Thanks for the suggestion!