Azure Runbook - Get a file from Azure File System Storage

耗尽温柔 提交于 2020-01-02 07:22:07

问题


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.


回答1:


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.




回答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.



来源:https://stackoverflow.com/questions/50531989/azure-runbook-get-a-file-from-azure-file-system-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!