5

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.

Adavesh
  • 557
  • 5
  • 9

2 Answers2

5

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.

  • Can you not use the following to eliminate the Automation variable: $sourceKey = Get-AzureRmStorageAccountKey -ResourceGroupName $SourceResourceGroupName -Name $SourceStorageAccountName $sourceContext = New-AzureStorageContext -StorageAccountName $SourceStorageAccountName -StorageAccountKey $sourceKey[0].Value – Tom Padilla Feb 28 '19 at 21:27
2

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.

Anatoli Beliaev
  • 1,614
  • 11
  • 13