using powershell to get a string out of one file and replace this value in another file

77 Views Asked by At

i'm trying to get a string out of a file and want this string to be inserted/replaced in another file with Powershell commands

file1: "buildnumber": "[it's a value that contains the last commit id]" file2: "buildnumber": "xxxxxxxx"

File 1 (app.config.json) come direct from the pipeline with the last commit id, File2 (app.config.json_pipeline) is a template for the testers, but file2 should also contain current "buildnumber"

Further i want to embed this Powershell command into a batch script routine. as of this i used to execute

this is my statement, but it doesn't change the value in the app.config.json

powershell -Command "(Get-Content C:\[path_to_file]\app.config.json).replace('Select-String -Pattern "BuildNumber*"', '(Get-Content "C:\[path_to_file]\app.config.json_pipeline" | Select-String -Pattern "BuildNumber*")') | Set-Content C:\[path_to_file]\app.config.json"

Maybe somebody has an idea, i got a little stuck with this.

i'm afraid that i chose the wrong way the retrieve that needed value.

Don't really know i PS "replace" can handle "select-String" as value handler.

I want to keep it easy best as one line statement.

Many thanks in advance

i want to keep it easy, but don't know if my approach is the right one. i use get-content.replace | set-content very often to replace static values, but with this every changing value i'm not getting further

0

There are 0 best solutions below