Last active
December 23, 2023 01:28
-
-
Save Wind010/cf4a40388a5cdd83c815257172c1dbb1 to your computer and use it in GitHub Desktop.
Script to convert Advanced Edit format of WebApp/Azure Function to local.settings.json format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This works if your function app is functional :) | |
# func azure functionapp fetch-app-settings <function app name> | |
# If it isn't, use this. | |
# { | |
# "IsEncrypted": false, | |
# "Values": { | |
# "AzureWebJobsStorage": "UseDevelopmentStorage=true", | |
# "AzureWebJobsDashboard": "UseDevelopmentStorage=true", | |
# "FUNCTIONS_WORKER_RUNTIME": "dotnet" | |
# }, | |
# "ConnectionStrings": { | |
# "MyDb": "<my connection string>" | |
# }, | |
# "Host": { | |
# "CORS": "*" | |
# } | |
# } | |
# Your JSON array | |
$jsonArray = @' | |
[ | |
{ | |
"name": "APPINSIGHTS_INSTRUMENTATIONKEY", | |
"value": "123", | |
"slotSetting": true | |
} | |
] | |
'@ | |
# Convert the JSON array to PowerShell objects | |
$objects = ConvertFrom-Json $jsonArray | |
# Create a hashtable to store the key-value pairs | |
$convertedObject = @{} | |
# Loop through each object in the array and extract the name and value | |
foreach ($obj in $objects) { | |
$convertedObject[$obj.name] = $obj.value | |
} | |
# Convert the hashtable to JSON format | |
$convertedJson = ConvertTo-Json $convertedObject | |
# Output the converted JSON in the desired format | |
Write-Output $convertedJson |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment