Artifact 39cb6d4721afa8b8192ba1527718a55c2ac2419ce78941c827314fe0a68fc0fb:
- File
Set-JavaPropertyFileValu.ps1
— part of check-in
[c11aab4b3e]
at
2018-06-10 13:43:51
on branch trunk
— Function to update a property value within a Java properties file
(user:
Michael Craig
size: 1313)
# 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"
}
}