上传到 AzureFile Storage 而不是 Blob

Upload to AzureFile Storage Not Blob

虽然我不是 powershell 脚本大师,但我很难将一些压缩文件上传到我的 Azure 文件存储。

我尝试了以下脚本 微软指南(“https://docs.microsoft.com/sv-se/powershell/module/azure.storage/set-azurestoragefilecontent?view=azurermps-1.2.9”)

$StorageAccountName = "MyAccountName"
$StorageAccountKey = "TheKeyThat I have"
$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName `
         -StorageAccountKey $StorageAccountKey
         Set-AzureStorageFileContent archive archive\Test\ C:\Users\User\Desktop\MoveFrom\*.* -Context $context'

我遇到的问题是出现此错误

Set-AzureStorageFileContent : The specified source file 'archive\Test\' was not found.
At line:5 char:10
+          Set-AzureStorageFileContent archive archive\Test\ C:\Users\User\De ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureStorageFileContent], FileNotFoundException
    + FullyQualifiedErrorId : FileNotFoundException,Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet.SetAzureStorageFileContent

共享名为存档,在存档内我们有不同的文件夹,其中一个文件夹名为 Test。所以我不明白为什么它抱怨缺少源文件?

首先,我认为您不能使用 Set-AzureStorageFileContent 上传文件夹。您需要上传单个文件。

此外,此 Cmdlet 的使用存在问题。请参考文档here。根据文档,请尝试以下操作:

$source = "<path to source file>"
Set-AzureStorageFileContent -ShareName "archive" -Source $source -Path "Test" -Context $ctx

如果您想上传 Azure File Share 中的文件夹,我建议您看一下 AzCopy。要从一个文件夹上传所有文件,您可以像这样使用 AzCopy:

AzCopy /Source:C:\myfolder /Dest:https://myaccount.file.core.windows.net/myfileshare/ /DestKey:key /S