# encoding: ascii
# api: powershell
# title: Set-JavaPropertyFileValu
# description: Function to update a property value within a Java properties file
# version: 0.1
# type: function
# author: Michael Craig
# license: CC0
# function: Set-JavaPropertyFileValue
# x-poshcode-id: 4629
# x-archived: 2015-05-04T22:25:44
# x-published: 2015-11-21T18:57:00
#
#
function Set-JavaPropertyFileValue($propFile, $propName, $propValue){
[string]$finalFile=""
if (test-path $propFile){
write-verbose "Found property file $propFile"
write-verbose "Read propfile"
$file = gc $propfile
foreach($line in $file){
if ((!($line.StartsWith('#'))) -and
(!($line.StartsWith(';'))) -and
(!($line.StartsWith(";"))) -and
(!($line.StartsWith('`'))) -and
(($line.Contains('=')))){
write-verbose "Searching for: $propName"
$property=$line.split('=')[0]
write-verbose "Looking: $property"
#split line, left side if propName right side is value
if ($propName -eq $property){
write-verbose "found property name"
$line="$propName=$propValue"
}
}
$finalFile+="$line`n"
}
$finalFile | out-file "$propFile" -encoding "ASCII"
}else
{
write-error "Java Property file: $propFile not found"
}
}