Can not find your Azure storage credential

In this Azure PowerShell article, we will discuss the syntax of the Get-AzStorageFile PowerShell command and how to fix the error “can not find your Azure storage credential. Please set current storage account using “set-azsubscription” or set the “azure_storage_connection_string” environment variable.” which I got while executing the Get-AzStorageFile PowerShell command for one of the critical requirements.

Can not find your Azure storage credential

I was executing the PowerShell command below.

Get-AzStorageFile -ShareName "demotstestb4c6"

After executing the Get-AzStorageFile PowerShell command, I got the following complete error message.

Get-AzStorageFile : Can not find your azure storage credential. Please set current 
storage account using "Set-AzSubscription" or set the 
"AZURE_STORAGE_CONNECTION_STRING" environment variable.
At line:1 char:1
+ Get-AzStorageFile -ShareName "demotstestb4c6"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-AzStorageFile], ArgumentExcep 
   tion
    + FullyQualifiedErrorId : ArgumentException,Microsoft.WindowsAzure.Commands.Stora 
   ge.File.Cmdlet.GetAzureStorageFile

You can see the same error message below.

Can not find your Azure storage credential

Solution

To fix the error, I had to pass the storage context along with the Get-AzStorageFile PowerShell command. I have executed the PowerShell script below.

Connect-AzAccount
$mystrgActRG = "DEMORG2"
$mystrgActName = "demorg2913f"
$mystrgActKey = (Get-AzStorageAccountKey -ResourceGroupName $mystrgActRG -AccountName $mystrgActName).Value[0]
$mystrgActctx = New-AzStorageContext -StorageAccountName $mystrgActName -StorageAccountKey $mystrgActKey
Get-AzStorageFile -ShareName "demotstestb4c6" -Context $mystrgActctx

After executing the above script, I got the expected output as below

CloudFileDirectory       : Microsoft.Azure.Storage.File.CloudFileDirectory
LastModified             : 1/19/2023 7:14:44 AM +00:00
ShareDirectoryClient     : Azure.Storage.Files.Shares.ShareDirectoryClient
ShareDirectoryProperties : Azure.Storage.Files.Shares.Models.ShareDirectoryProperties
ListFileProperties       : Azure.Storage.Files.Shares.Models.ShareFileItem
Context                  : Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext
Name                     : data


CloudFileDirectory       : Microsoft.Azure.Storage.File.CloudFileDirectory
LastModified             : 1/19/2023 7:13:09 AM +00:00
ShareDirectoryClient     : Azure.Storage.Files.Shares.ShareDirectoryClient
ShareDirectoryProperties : Azure.Storage.Files.Shares.Models.ShareDirectoryProperties
ListFileProperties       : Azure.Storage.Files.Shares.Models.ShareFileItem
Context                  : Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext
Name                     : LogFiles


CloudFileDirectory       : Microsoft.Azure.Storage.File.CloudFileDirectory
LastModified             : 1/19/2023 7:13:09 AM +00:00
ShareDirectoryClient     : Azure.Storage.Files.Shares.ShareDirectoryClient
ShareDirectoryProperties : Azure.Storage.Files.Shares.Models.ShareDirectoryProperties
ListFileProperties       : Azure.Storage.Files.Shares.Models.ShareFileItem
Context                  : Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext
Name                     : site

You can check out the same output as below

Get-AzStorageFile

Wrapping Up

In this Azure PowerShell article, we discussed the syntax of the Get-AzStorageFile PowerShell command and how to resolve the error “Get-AzStorageFile: Can not find your Azure storage credential.” I hope this information helps. Thanks for reading this article !!!

You may also like the following articles below

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!