0

Currently, I'm performing this command on linux shell:

for binary in $(curl -s -X GET "${FHIR_SERVER}/\$export-poll-status?_jobId=${JOB_ID}" -H "Authorization: Bearer ${ACCESS_TOKEN}" | jq -r ".output[].url"); \
  do wget --header="Authorization: Bearer ${ACCESS_TOKEN}" ${binary} -O ->>patients-pre.json;
done

Is there any way to get this on powershell?

9
  • PowerShell (Core) is a cross-platform environment. Are you looking for a true cross-platform solution, or is a solution that relies on standard utilities available on a given platform - such as Linux distros - acceptable? Commented Jan 2, 2022 at 23:19
  • @mklement0 - Are you inferring that PowerShell is not truly cross-platform? This question is coming from someone who hasn't played with it at all on Linux. Commented Jan 3, 2022 at 0:07
  • 2
    @T-Heron. How do you reconcile your claim with my previous statement of "PowerShell (Core) is a cross-platform environment"? My point was: A cross-platform shell can be used in one of two ways: (a) In a platform-specific way, relying on a given platform's native abilities or (b) in a truly platform-agnostic way, using only features available on all supported platforms. Needless to say, (b) either requires more work or may not even be possible, depending on the use case. (a) requires specifying which platform should be targeted. Commented Jan 3, 2022 at 0:14
  • 1
    @T-Heron, also, in the future, please refrain from gratuitous ad-hominem statements such as "is coming from someone who hasn't played with it at all on Linux". They add nothing to the conversation and only serve to antagonize. Commented Jan 3, 2022 at 0:16
  • The official names are pwsh.exe which is Powershell (without core in the name) verses powershell.exe which is WindowsPowershell The docs follow this Commented Jan 4, 2022 at 0:34

1 Answer 1

2

While not knowing exactly the format of your incoming json, I'd use something like this in powershell / pwsh:

curl ... | % { wget (convertto-json $_).output.url } >> patients-pre.json

The % is an alias for ForEach-Object which will iterate over objects (or lines of text) sent from the left side of the pipe. Powershell is interesting because when using the pipe symbol, there's an implicit for / do / done operation going on.

curl is on all modern versions of windows, so you don't need to change that. wget isn't, but you could install it, or use curl again.

If you want to go full powershell, look at invoke-restmethod ( https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.2 ). This can do the jobs of both curl and wget in your example, and also automatically handle json returns to give you a structured object instead of text (which is what convertto-json is doing above.)

Sign up to request clarification or add additional context in comments.

1 Comment

Also see the gh command line utility https://cli.github.com/manual/gh It 1] is made for scripting (whether bash/powershell/etc) 2] simplifies / handles authenticating for the github API 3] has a --json parameter, making it easy to parse and 4] has jq queries built-in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.