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?