Save files to Azure fileshare in the sub directory

717 views Asked by At

Below is the runbook code I am using to save the file to azure fileshare. But unable to save in subdirectory.

#Set the context using the storage account name and key
$context = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey 


$s = Get-AzureStorageShare "X1" –Context $context


$ErrorLogFileName = "Test.csv" 
$LogItem = New-Item -ItemType File -Name $ErrorLogFileName
      $_ | Out-File -FilePath $ErrorLogFileName -Append


Set-AzureStorageFileContent –Share $s –Source $ErrorLogFileName 

Here I have a folder structure like X1/X2. But unable to get there and save the Test.csv. infact able to save it X1 folder on the Azure fileshare. Any idea ?

Thanks in Advance

1

There are 1 answers

0
Ivan Glasenberg On

You can specify the -Path parameter for Set-AzureStorageFileContent.

For example, the file share is X1, and there is a folder X2 inside X1. Then you can use the command below:

Set-AzureStorageFileContent –Share "X1" –Source $ErrorLogFileName -Path "X2" -Context $context

By the way, the command you're using is old, please try to consider using the latest az powershell command. For example, you can use Set-AzStorageFileContent instead of Set-AzureStorageFileContent(if you try to use the az module, then please replace all the old commands with the new ones).