1

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?

4

2 回答 2

1

您可以使用以下 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

于 2019-01-29T05:29:23.277 回答
1

我知道的老问题,但现在可以使用 ARM 模板创建文件共享 - 在 ARM 中是这样的:

    {
      "type": "Microsoft.Storage/storageAccounts/fileServices/shares",
      "apiVersion": "2019-06-01",
      "name": "[concat(parameters('storageAccountName'), '/default/', parameters('fileShareName'))]",
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
      ]
    }

或者更简单的二头肌:

resource myStorage 'Microsoft.Storage/storageAccounts/fileServices/shares@2019-06-01' = {
  name: '${storageAccount.name}/default/${fileShareName}'
}
于 2021-05-21T12:17:24.127 回答