Public/ps1/Configuration/Set-ConfigurationValue.ps1
function Set-ConfigurationValue{ param($name, $value, [switch]$secure) $folder = Get-LeftConnectConfigurationFolder if ($secure) { $value = ConvertTo-SecureString -Force -AsPlainText $value | ConvertFrom-SecureString } if (Test-Path "$folder\config.json") { } else { "{}"|set-content "$folder\config.json" } $config = Get-Content "$folder\config.json" | ConvertFrom-Json # the prpoerty does not exist if ($config.$name -ne $null ) { $config.$name = $value } elseif (@($config.psobject.Properties).Count -ge 1 -and $config.PSobject.Properties.Name.Contains($name)) { $config.$name = $value } else { $config | Add-Member -MemberType NoteProperty -Name $name -Value $value } $config | ConvertTo-Json | Set-Content "$folder\config.json" } |