Private/Set-KeyValue.ps1
|
Function Set-KeyValue { ################################################################################ ##### ##### ##### Update value in JSON File ##### ##### ##### ################################################################################ Param([string] $key, [string]$NewValue) $CurrentFunction = Get-FunctionName Write-Log -Message "### Start Function $CurrentFunction ###" $StartRunTime = (Get-Date).ToString($Script:DateFormatLog) #################### main code | out- host #################### $json = Get-Content -Path $Script:ConfigFile | ConvertFrom-Json ($json.DefaultParameter.Setting | Where-Object { $_.Name -eq $key }).Value = $NewValue $json | ConvertTo-Json -Depth 10 | Set-Content -Path $Script:ConfigFile -Force Write-Log -Message " >> Set '$key' to '$NewValue'" ######################## main code ############################ $runtime = Get-RunTime -StartRunTime $StartRunTime Write-Log -Message " Run Time: $runtime [h] ###" Write-Log -Message "### End Function $CurrentFunction ###" } |