用于在 blob 容器内创建子目录并向其中插入一些数据的 PowerShell 脚本

Pra*_*eep 1 powershell azure azure-storage azure-blob-storage

我有多个 Azure 存储帐户。我想在 Azure 存储 blob 容器内创建文件夹结构,并使用 PowerShell 向其中插入一些数据。

那么,任何人都可以建议我如何编写 PowerShell 脚本来在 blob 容器内创建子目录并向其中插入一些数据。

小智 6

在 Azure 存储 Blob 容器中并不真正支持创建文件夹,将文件上传到容器时会创建文件夹作为路径的一部分,因此不存在仅创建空文件夹的单独操作。例如:

folder1/image.png
folderA/folderB/image2.png
Run Code Online (Sandbox Code Playgroud)

SDK有API支持根据“文件夹”路径获取文件。

“创建”folder1 的 Powershell 示例是:

Connect-AzureRmAccount

$storageAccount = Get-AzureRmStorageAccount -ResourceGroupName 'myresourcegroup' `
-Name 'storageaccount' 

Set-AzureStorageBlobContent -File C:\tmp\0001.png `
-Container files `
-Blob 'folder1/0001.png' `
-Context $storageAccount.Context
Run Code Online (Sandbox Code Playgroud)

这将分别“创建”folder1 并将 0001.png 上传到该文件夹