functions/public/Update-AppSettings.ps1
function Update-AppSettings { param ( [Parameter(Mandatory = $true)] [string] $appSettingsPath, [Parameter(Mandatory = $true)] [hashtable] $appSettingsValues ) $appSettings = (Get-Content $appSettingsPath -Raw) | ConvertFrom-Json foreach ($appSettingValue in $appSettingsValues.GetEnumerator()) { if ($appSettings.psobject.properties.name -notcontains $appSettingValue.Key) { $appSettings | Add-Member -Type NoteProperty -Name $appSettingValue.Key -Value $appSettingValue.Value Write-DosMessage -Level "Information" -Message "Added $($appSettingValue.Key) to the appSettings.json file" } else { if ($appSettings."$($appSettingValue.Key)" -ne $appSettingValue.Value) { $appSettings."$($appSettingValue.Key)" = $appSettingValue.Value Write-DosMessage -Level "Information" -Message "Updated $($appSettingValue.Key) in appSettings.json file" } } } $appSettings | ConvertTo-Json -Depth 10 | Set-Content $appSettingsPath Write-DosMessage -Level "Information" -Message "Finished updating appSettings.json file" } |