1

I want to use Azure Automation to deploy Files Share snapshots scheduler, I create a runbook, but I can't find the cmdlet at the internet.

(there have some samples about how to create a snapshot from 0, but I want to create the existing Files share snapshots, and I tried to change the cmdlet to make it work, it was failed.).

Is there someone can tell me about the right cmdlet or some way to schedule that with Azure Automation.

Thanks so much.

Arthur
  • 103
  • 11
  • Do you mean you want to snapshot an existing files share? – Ivan Glasenberg Dec 14 '18 at 02:49
  • yes. Just now I found something, I use this cmdlet to get my existing StorageAccount : $resourceGroup = "myexistingresourcegroup" $storageAccountName = "myexistingstorageaccount" $storageAccount = Get-AzureRmStorageAccount -ResourceGroupName $resourceGroup ` -Name $storageAccountName But when I went to the next step, it shows "Could not get the storage context." – Arthur Dec 14 '18 at 04:09
  • https://learn.microsoft.com/ja-jp/azure/storage/files/storage-how-to-use-files-powershell https://learn.microsoft.com/ja-jp/azure/storage/common/storage-powershell-guide-full Here are some Webs maybe is useful, but I don't know how to shapshot an existing files share. – Arthur Dec 14 '18 at 04:14
  • I'll post my answer a few seconds later, if any concerns please let me know. – Ivan Glasenberg Dec 14 '18 at 04:17

1 Answers1

0

Please try the code below in your runbook, it works at my side(if you want to parameterized the account name / key and fileshare name, you can do it your self or ask me for help):

$context = New-AzureStorageContext -StorageAccountName your_storage_account -StorageAccountKey your_storage_account_key

$share = Get-AzureStorageShare -Context $context -Name your_file_share_name

$snapshot = $share.Snapshot()

Note that if it prompts that the Snapshot() method is not found, you should install the azure.storage module from your automation account -> Modules gallery, and import this module. It will take a few minutes to take effect.

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • @Arthur, could you please help mark it as answer? thanks:) – Ivan Glasenberg Dec 14 '18 at 07:30
  • @Arthur, I have never tried delete or retain them, but it should be just some powershell script. If you have any questions, just feel free to post your issue to stackoverflow, we can help you solve it. – Ivan Glasenberg Dec 14 '18 at 07:32