I am trying to parse appsettings.json file to extract the connection string using a batch script.
I am spreading the command on multiple lines as it is quite long and hard to maintain:
set ps_GetConnectionString=(Get-Content 'appsettings.json' -Raw)^
| ForEach-Object { $_ -replace '(?ms)/\*.*?\*/' -replace '[\s\t]+//.*' }^
| ConvertFrom-Json^
| Select -expand ConnectionStrings | Select default^
| ConvertTo-Csv -Delimiter ~
When I run this, I get an error: 'ForEach-Object' is not recognized as an internal or external command.
How do we properly break this command into multiple lines, store in a variable in order to make the powershell -command call much shorter?
.batfile? Could you not dump the PowerShell portion into aps1/ script file and execute that way? What's the reasoning behind a separate.batcalling PowerShell script commands?powershell -commandin order to perform certain tasks that are not very easy to do with batch only. I am trying to avoid writing everything in powershell due to security restrictions^batch line continuation symbol work, it has to be outside of double quoted strings, which you OTOH *need to escape PowerShell pipe symbols and content not destined for batch => that exactly does the batch error message mean.