0

So I have a Azure file storage which you can map a collective drive too. At the moment it's chosen as the X drive but I'm in a little problem becuase sometimes I lose connection to the drive because it goes IDLE.

I followed this guide that provided me how to set evrything up (" https://ppolyzos.com/2016/09/09/map-network-drive-to-azure-storage-account-file-storage/")

I wanted to move some files to that specific folder through a timed schedule with the following script.

With CreateObject("Scripting.FileSystemObject")
    .MoveFile "YourFolder\*.*", "X:\AzureFolder"
End With

The above vbscript worked like a charm but as I mentioned the azure file storage actually goes IDLE and the job failes.

So my plan now was to actually create a powershell script that has the authentication values set as hard variables and then just move the files as the above vbscript does. Does anyone know if there are some open source code where someone has done something similar?

I did finde some script on the net ( " https://gallery.technet.microsoft.com/scriptcenter/Recursively-upload-a-bfb615fe " ) But they dont seem to work.

Would be pleased if someone can point me in the right direction or provide with a helpfull guide.

Thanks!

1

1 Answer 1

1

The following lines uploads local files into azure blob storage

$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName ` -StorageAccountKey $StorageAccountKey
$ContainerName = "webimages"
New-AzureStorageContainer -Name $ContainerName -Context $ctx -Permission Blob
$localFileDirectory = "X:\Temp\AzureFilesToUpload\"
$files = Get-ChildItem -Path $localFileDirectory -Recurse -File
foreach($file in $files)
{
    $localFile = $localFileDirectory+$file
    Set-AzureStorageBlobContent -File $localFile -Container $ContainerName `-Blob $BlobName -Context $ctx
}
Get-AzureStorageBlob -Container $ContainerName -Context $ctx | Select Name

Below lines uploads local files into azure files section of storage account instead of blob

$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName ` -StorageAccountKey $StorageAccountKey  
$s = New-AzureStorageShare $filesharename –Context $ctx # to create new file share
$localFileDirectory = "X:\Temp\AzureFilesToUpload\"
$files = Get-ChildItem -Path $localFileDirectory -Recurse -File  
foreach($file in $files)  
{  
    $localFile = $localFileDirectory+$file  
    Set-AzureStorageFileContent –Share $s –Source $localFile  
}  
  # if you don’t want them in the root folder of the share, but in a subfolder?  
New-AzureStorageDirectory –Share $s –Path $foldername
foreach($file in $files)  
{  
    $localFile = $localFileDirectory+$file  
    Set-AzureStorageFileContent –Share $s –Source $localFile –Path $foldername  
}  
Sign up to request clarification or add additional context in comments.

11 Comments

I've seen this but is there no difference in Azure Blob storage compared to Azure File Storage?
I've listed the lines to Azure file storage through powershell in above edit.Azure file storage offers shared storageusing the standard SMB protocol. Azure virtual machines and cloud services can share file data across application components via mounted shares, and on-premises applications can access file data in a share via the File service REST API while Blob Storage stores unstructured object data. A blob can be any type of text or binary data, such as a document, a media file, or an application installer. Blob storage is also referred to as Object storage.
I've added some comments in the script which is provided becuase I'm wondering what to place in correct spot. Please look below if it looks correct.
$ctx = New-AzureStorageContext MyStorrageAccountName $StorageAccountName ` TheStorageAccountKey-EndsWith== usually? $StorageAccountKey $s = New-AzureStorageShare $filesharename filesharecontext? is this the shares name? $ctx New-AzureStorageDirectory thesharesname $s pathInTheShare? $foldername foreach($file in $files) { $localFile = $localFileDirectory+$file Set-AzureStorageFileContent thesharesname $s LokalFilderWhereFileisStored $localFile pathInTheShare? $foldername }
examples $StorageAccountKey=AxgCWYNr0+2LT7aDYZPROrAUghfj6xYRE17gHaCXcuCd3vLhnSHeRfF1LJfrwjOQxayOaZhcH750/ju9j3ncTw== $filesharename=images #it is the file share name $foldername=webimages #it is the name of subfolder inside the share I've hardcoded the below lines for better understanding $s = New-AzureStorageShare images –Context $ctx # if file share doesn't exist in azure portal $s = Get-AzureStorageShare images –Context $ctx # if fileshare already exists in azure portal New-AzureStorageDirectory –Share $s –Path webimages
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.