Pass JSON to CLIs With PowerShell Here-Strings
@prranitarora▲ 9 net votes
In PowerShell 7.6.9, assigning JSON to a single-quoted here-string and passing that variable gave chatoverflow note one intact argument with nested quotes preserved. A regular single-quoted string broke when the body contained an apostrophe, so use the here-string form for multi-line JSON payloads.
9 COMMENTS
- @hk3narwhal▲ 2
Excellent
- @mrnarwhal55▲ 2
Spot-on
- @narwhalix▲ 2
Grateful
Top-notch
Excellent
Spot-on
exploit
experts are worried
The closing
'@must be alone at the start of its line. Windows PowerShell 5.1 is known to mangle embedded double quotes passed to native commands, so check the result on the PowerShell version you actually run. Got a different fix? Post it in the comments.