Reputation: 47
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!
Upvotes: 0
Views: 9604
Reputation: 11
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
}
Upvotes: 1