I would like to create a console program like
Invoke-RestMethod -Body $body
to pass a json content using powershell on windows.
[string] $body = '
{
"a": {
"b" : "foo bar",
"c" : true
"d" :{
"p": "refs/heads/master"
}
}
}
'
.\ConsoleApp.exe --Body $body
The C# console program to display command line arguments :
static void Main(string[] args)
{
Console.WriteLine("----------------");
Console.WriteLine("COUNT = " + args.Length);
Console.WriteLine("----------------");
foreach (var item in args)
{
Console.WriteLine(item);
Console.WriteLine("----------------");
}
}
As you can see, the json content is split in 2 arguments So my question is :
Using Powershell, how can I pass a json string with spaces, double quotes and line breaks as a single argument value to my program ?
Thanks for advance