'Unexpected token ':"Condeco"' in expression or statement

I have one DevOps release pipeline. When I update my app service it automatically deletes any app configuration added previously by the user. So I want to get all the app settings and store them into variable then after the app service update again add them back to the app setting.

To store app setting into variable

$webApp = Get-AzureRMWebApp -ResourceGroupName $(Parameter.ResourceGroupName) -Name $(Parameters.AppName)  
$appSetting = $webApp.SiteConfig.AppSettings
$hash = @{}
foreach($kvp in $appSetting) {
    $hash[$kvp.Name] = $kvp.Value
}
Write-Host ($hash | Out-String)
$jsonObject = [PSCustomObject]$hash
$convertJson = $jsonObject | ConvertTo-JSON -Depth 100 -Compress
Write-Host "JSON : " $convertJson
Write-Host "##vso[task.setvariable variable=storeAppSetting;]$convertJson"

Print JSON value

{"issuer":"Condeco","EnterpriseRedisAccess":"true","RedisConnectionString":"Redis","d":"d","APIBaseURL":"https://abc.azurewebsites.net","secret":"XXXXX=","NotificationPusher":"https://abc.xyz.com/NotificationPusher","audience":"XXXXX","SwaggerTitle":"Condeco","EnterpriseURL":"https://abc.xyz.com/"}

Now I want to use that variable to set the app setting again

Write-Host "Get Variable : " $(storeAppSetting)

Error

2022-04-26T09:03:29.7642657Z ##[error]At D:\a\_temp\302fc4cc-24ff-4ad1-b04e-f4b1331dc00f.ps1:2 char:35
+ Write-Host "Get Json : " {"issuer":"Condeco","EnterpriseRedisAccess": ...
+                                   ~~~~~~~~~~
Unexpected token ':"Condeco"' in expression or statement.

At D:\a\_temp\302fc4cc-24ff-4ad1-b04e-f4b1331dc00f.ps1:2 char:45
+ Write-Host "Get Json : " {"issuer":"Condeco","EnterpriseRedisAccess": ...
+                                             ~
Missing argument in parameter list.


Solution 1:[1]

We have tried the same command as you are using and getting the invalid cmdlt error as shown below.

enter image description here

And as suggested by @Remko, We have tried to use the same and not getting any errors.

"Instead of using Write-Host "Get Variable : " $(storeAppSetting) try to use this:- Write-Host "Get Variable : $($storeAppSetting)" "

OUTPUT DETAILS FOR REFERENCE:-

enter image description here

For more information please refer the below links:-

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AjayKumarGhose-MT