Get-AzStorageFile: Can not find your Azure storage credential

In this Azure PowerShell article, we will discuss how to fix the error “Get-AzStorageFile: Can not find your Azure storage credential” which I got while executing the Get-AzStorageFile PowerShell command for one of the critical requirements.

Get-AzStorageFile: Can not find your Azure storage credential

Recently, while I was executing the below PowerShell command, I got this error.

Get-AzStorageFile -ShareName "demotstestb4c6"

Below is the 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

Get-AzStorageFile Can not find your Azure storage credential

Get-AzStorageFile: Can not find your Azure storage credential [Solution]

To fix the error “Get-AzStorageFile: Can not find your Azure storage credential“, I had to pass the storage context along with the Get-AzStorageFile PowerShell command. So I have executed the below PowerShell script.

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

You may also like following the below articles

Wrapping Up

In this Azure PowerShell article, we discussed how to fix the error “Get-AzStorageFile: Can not find your Azure storage credential“. Hope this information helps. Thanks for reading this article !!!