I’m using Powershell to pull down some appsettings.json files for applications that are hosted in Azure Functions. I’m looping through the functions and pulling down the appsettings to later perform some operations on. The code looks something like:
# Where the appsettings json lives on the function/service
$pathToFile = "/site/wwwroot/appsettings.json"
# get scm site cred
$publishProfile = az webapp deployment list-publishing-credentials --name $functionApp.Name -g $functionApp.ResourceGroupName | ConvertFrom-Json
$credential = [PSCredential]::new("$($publishProfile.publishingUserName)", (ConvertTo-SecureString -AsPlainText $publishProfile.publishingPassword -Force))
$api = "$($publishProfile.scmUri)/api/vfs"
$jsonFileContent = Invoke-RestMethod -Credential $credential -Authentication Basic -Method Get -Uri "$api/$($pathToFile.Trim('/'))"
In the majority of cases, this is working well and $jsonFileContent
contains a powershell object that I can work with easily later. For some of the functions though, I can’t work out why the $jsonFileContent
appears to contain a string containing the JSON.
> $jsonfileContent.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
If I write it out to a file with a .json extension and open it, everything appears to be valid in terms of the composition of the JSON.
I can use Convert-ToJSON
and ConvertFrom-JSON
to freely transform it between a regular string and a json formatted string but I am struggling to convert it into something that’s easier to work with.
Any ideas what is going on here or what could be causing this?
Thanks