首页 > 解决方案 > How do I deploy file share within storage account using ARM template

问题描述

I can successfully create a storage account using an ARM template and I realize the ARM template does not directly support creating a file share on the storage account via any of the existing providers. I thought I would write a PowerShell script and use the custom script extension in the arm template but it seems like that can only run on a VM (typically used for post setup stuff on VM).

Is there a way to create the file share and child directory structure in PowerShell and have this executed after my ARM template is deployed?

标签: azure-resource-managerarm-templateazure-storage-account

解决方案


您可以使用以下 powershell:

创建共享

$storageAcct = Get-AzStorageAccount -ResourceGroupName xxx -Name yyy
New-AzStorageShare `
   -Name myshare `
   -Context $storageAcct.Context

创建文件夹。

New-AzStorageDirectory `
   -Context $storageAcct.Context `
   -ShareName "myshare" `
   -Path "myDirectory"

上传文件。

# this expression will put the current date and time into a new file on your scratch drive
Get-Date | Out-File -FilePath "C:\Users\ContainerAdministrator\CloudDrive\SampleUpload.txt" -Force

# this expression will upload that newly created file to your Azure file share
Set-AzStorageFileContent `
   -Context $storageAcct.Context `
   -ShareName "myshare" `
   -Source "C:\Users\ContainerAdministrator\CloudDrive\SampleUpload.txt" `
   -Path "myDirectory\SampleUpload.txt"

来源:https ://docs.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-powershell


推荐阅读