Update the properties file using powershell


I want to update below property file contents using powershell and replace ${BuildPath} with location = D:\Data\Sample\lib


Could some one please help me logic on powershell to update this property file.


So you have a file with those properties in it yes? Who's to say how it was created or if that is the only contents? Lets just assume you have a file with lots of properties other than that just in case. You want to navigate the file replacing all occurrences* of ${BuildPath} with D:\Data\Sample\lib

$replacePath = "D:\Data\Sample\lib"
$newFile = Get-Content c:\temp\file.ini | ForEach-Object{
    $_ -replace '\${BuildPath}',($replacePath -replace '\\',"\\")
$newFile | Set-Content c:\temp\file.ini

This would give the following output in c:\temp\file.ini


* regex will only replace the first occurrence on each line. Doubt there would be more than one anyway.

Welcome to SO

This community works alot better if you show some effort first. You question did not show that. I only saw a request for an answer. We are here to support programmers and programming enthusiasts. We are not a code writing service.