I’m trying to convert JSON file which is present in storage account data into Powershell object. But I’m not getting the proper output. Output does not contain proper values.
My code:
$storageAccountKey = "xxxx"
$Context = New-AzStorageContext -StorageAccountName 'xxxx' -StorageAccountKey $storageAccountKey
$b='C:TempScheduled.json'
Get-AzureStorageFileContent -Path $b -ShareName "file-share-name"
$newScheduledRules = Get-Content -Raw $b | ConvertFrom-Json
Write-Output ("########newScheduledRules::###########" + $newScheduledRules)
Output:
Could not get the storage context. Please pass in a storage context or set the current storage context.
########newScheduledRules::###########@{Scheduled=System.Object[]; Fusion=System.Object[]; MLBehaviorAnalytics=System.Object[]; MicrosoftSecurityIncidentCreation=System.Object[]}
2
Answers
It seems the
Get-AzureStorageFileContent
is missing-Context
parameter. It should be something like thisI have reproduced in my environment and got expected results as below and followed below process and followed Microsoft-Document:
Scheduled.json:
Firstly, I have created Storage account and then added a Scheduled.json in file share as below:
Now i have created a runbook and excuted below script in runbook as below:
Output:
Here $out is the Destination Variable.
-Path should be Only the file name
Scheduled.json
inGet-AzStorageFileContent
command.