Adavesh
Adavesh

Reputation: 559

Azure Runbook - Get a file from Azure File System Storage

I am creating a Azure workflow runbook wherein I have to get a file from Azure File System Storage and publish that to a azure web app.

I tried with New-PSDrive but that command is not supported in runbook (even InlineScript doesn't work). Could anyone help me with the script. In the below code I need to populate file path from azure file system.

$Conn = Get-AutomationConnection -Name AzureRunAsConnection
    Connect-AzureRmAccount -ServicePrincipal -Tenant $Conn.TenantID `
                           -ApplicationId $Conn.ApplicationID `
                           -CertificateThumbprint $Conn.CertificateThumbprint
$zipFilePath = ???
Publish-AzureWebsiteProject -Name $siteName -Package $zipFilePath 

I searched a lot but couldn't find much information on this.

Upvotes: 5

Views: 7590

Answers (2)

Jeff Gebhardt - MSFT
Jeff Gebhardt - MSFT

Reputation: 309

Are you referring to a file in a Azure Storage account? If so, that is pretty easy to accomplish. Add the following to your Runbook, filling in the required information:

$StorageAccountKey = Get-AutomationVariable -Name 'storageKey'

$Context = New-AzureStorageContext -StorageAccountName 'your-storage' ` 
-StorageAccountKey $StorageAccountKey

Get-AzureStorageFileContent -ShareName 'your-share' -Context $Context `
-path 'your-file' -Destination 'C:\Temp'

$filePath = Join-Path -Path 'C:\Temp' -ChildPath 'your-file'

You also need to create an variable in your Automation Account, called "storageKey" containing your Storage Accounts key.

Upvotes: 5

Anatoli Beliaev
Anatoli Beliaev

Reputation: 1664

Mounting Azure File share as a drive is not currently supported in Automation cloud jobs, though it will probably be supported in a few months. In the meantime, use the Get-AzureStorageFile command from the Azure.Storage module to retrieve the file to a temp folder.

Alternatively, run this job on a Hybrid worker. In this case, make sure all the prerequisites are met in order to mount the share as a network drive.

Upvotes: 2

Related Questions