0

I've inherited a Powershell script that runs in an Azure RunBook. In the script we need to read a StorageQueue. I'm having issues connecting to the StorageAccount.

The following snippet fails on New-AzureStorageContext, because the $connectionString is Empty.

$storageContext = (Get-AzureRMStorageAccount | Where { $_.StorageAccountName -eq $storageAccountName }).Context 
$connectionString = $storageContext.ConnectionString
$storageContextNew = New-AzureStorageContext -ConnectionString $connectionString
$queues = Get-AzureStorageQueue -Prefix $queueNamePrefix -Context $storageContextNew

How can I fix this so I have the ConnectionString and can connect to the Queue?

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
Felix Planjer
  • 89
  • 1
  • 6
  • Turned out that our runbook was using some *very* outdated versions of packages, which I found out because some other packages where missing. Updating those packages fixed the issue... – Felix Planjer May 17 '19 at 12:27

1 Answers1

1

Try the command as below to get the $context, then use it to get the queues.

$SAResourceGroupName="<resource group name>"
$StorageAccountName="<storage account name>"
$StorageAccountKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $SAResourceGroupName -AccountName $StorageAccountName).Value[1]
$context=New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$queues = Get-AzureStorageQueue -Prefix testqueue -Context $context

enter image description here

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
  • This will not work in my situation, because I do not know the ResourceGroup. I have to search all storageaccounts for one with the correct name. – Felix Planjer May 17 '19 at 12:29