Tuesday, January 16, 2018

Powershell command to change properties file



1.   To update App.properties file with Key=Value pair



$data =[io.file]::ReadAllText("C:\Resources\ConfigFiles\app.properties")
$data = $data -replace "Environment=(.+)","Environment=RC"
[IO.File]::WriteAllText("C:\Resources\ConfigFiles\app.properties", $data.TrimEnd())




2. To update XML file with different section and Key=Value pair



[xml] $xml = Get-Content "C:\Resources\ConfigFiles\app.properties"
$($xml.configuration.appSettings.add | Where-Object { $_.key -eq "Environment" }).value = "RC"

$xml.Save("C:\Resources\ConfigFiles\app.properties") 


No comments:

Post a Comment