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.
Table of Contents
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.GetAzureStorageFileYou can see the same error message below.

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 $mystrgActctxAfter 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

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

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
