0
votes

To create a SAS Token was the aim and required as a precondition setting desired storage as current storage:

Running the following command

Set-AzureRmCurrentStorageAccount -ResourceGroupName $StorResourceGroupName -Name $StorageAccountName 

throws error:

Set-AzureRmCurrentStorageAccount : The Resource 'Microsoft.Storage/storageAccounts/yoursites' under resource group 'Default-Storage-EastUS' was not found. At line:1 char:1 + Set-AzureRmCurrentStorageAccount -ResourceGroupName $StorResourceGroupName -Name ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmCurrentStorageAccount], CloudException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Management.Storage.SetAzureRmCurrentStorageAccount

And this was throwing error for New-AzureStorageBlobSASToken -Container $StorageContainer -Blob $blobname -Permission r -ExpiryTime (Get-Date).AddHours(2.0) -FullUri

How to byepass this issue?

2

2 Answers

2
votes

I could think of 2 reasons why you may be getting this error:

  1. Storage account does not belong to this resource group (as indicated by the error).
  2. Storage account is a Classic storage account (I'm guessing this by the name of the Resource group).

Please see if one of them is indeed the case.

0
votes

The easy alternative I was able to apply was to create a storage context and pass the context parameter additionally.

Example :-

#Set Active Storage to Template Storage Context
$StorageKey = Get-AzureStorageKey -StorageAccountName $StorageAccountName;
$StorageContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageKey.Primary;
$now = Get-Date

#Create SAS token with temporary access 
New-AzureStorageBlobSASToken -Container $servicetemplateStorageContainer -Blob $blobname -Context $StorageContext -Permission r -ExpiryTime (Get-Date).AddHours(2.0) -FullUri

Hope this helps a straight reference for someone in similar scenario.