Azure Runbook - 从 Azure 文件系统存储获取文件

Ada*_*esh 5 powershell azure-automation azure-runbook

我正在创建一个 Azure 工作流 Runbook,其中我必须从 Azure 文件系统存储获取一个文件并将其发布到 azure Web 应用程序。

我尝试使用 New-PSDrive 但 Runbook 不支持该命令(甚至 InlineScript 也不起作用)。谁能帮我写一下剧本。在下面的代码中,我需要从天蓝色文件系统填充文件路径。

$Conn = Get-AutomationConnection -Name AzureRunAsConnection
    Connect-AzureRmAccount -ServicePrincipal -Tenant $Conn.TenantID `
                           -ApplicationId $Conn.ApplicationID `
                           -CertificateThumbprint $Conn.CertificateThumbprint
$zipFilePath = ???
Publish-AzureWebsiteProject -Name $siteName -Package $zipFilePath 
Run Code Online (Sandbox Code Playgroud)

我搜索了很多,但找不到太多这方面的信息。

小智 5

您指的是 Azure 存储帐户中的文件吗?如果是这样,那就很容易实现了。将以下内容添加到您的 Runbook,填写所需信息:

$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'
Run Code Online (Sandbox Code Playgroud)

您还需要在自动化帐户中创建一个名为“storageKey”的变量,其中包含您的存储帐户密钥。