Reputation: 2882
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?
Upvotes: 1
Views: 4109
Reputation: 7578
Old question I know, but it is now possible to create file shares using ARM templates - something like this in 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'))]"
]
}
Or much simpler in bicep:
resource myStorage 'Microsoft.Storage/storageAccounts/fileServices/shares@2019-06-01' = {
name: '${storageAccount.name}/default/${fileShareName}'
}
Upvotes: 3
Reputation: 72211
you can use the following powershell:
Create share
$storageAcct = Get-AzStorageAccount -ResourceGroupName xxx -Name yyy
New-AzStorageShare `
-Name myshare `
-Context $storageAcct.Context
Create folder.
New-AzStorageDirectory `
-Context $storageAcct.Context `
-ShareName "myshare" `
-Path "myDirectory"
Upload file.
# 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"
Source: https://learn.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-powershell
Upvotes: 1