使用Azure自动化 - 图形Runbook - 将APIM备份到存储

时间:2016-10-05 20:14:23

标签: powershell azure-api-management azure-automation

我有一个图形Runbook,可以将Azure API Management实例备份到Azure存储。我曾多次在Powershell中使用过这种技术,但我想我会尝试使用图形化的Runbook。

这是我的Runbook: enter image description here

当我从New-AzureStorageContext获取存储上下文并尝试在Backup-AzureRmApiManagement中使用它时,我收到以下错误: enter image description here

以下是我将存储上下文从上一个活动挂钩到我的备份活动的方式:enter image description here

人们建议上下文被序列化,我应该使用InlineScript,但我不能让它工作。

以下是我认为的序列化上下文: enter image description here

很高兴让它发挥作用。

1 个答案:

答案 0 :(得分:1)

假设这是图形(不是图形化PowerShell 工作流程)Runbook,此处不应存在序列化问题。

最有可能的问题是,您的自动化帐户中的模块版本不匹配。该错误消息指示New-AzureStorageContext需要AzureStorageContext类型的参数,并且它接收AzureStorageContext类型的值。但是,不同的模块版本可以引用在不同程序集中定义的类型,并且该值不能自动转换为其他类型。例如,Azure.Storage(版本A)中的New-AzureStorageContext可能会返回AzureRtorageContext对象,该对象与AzureRM.ApiManagement(版本B)中Backup-AzureRmApiManagement所期望的类型不兼容。不幸的是,错误消息不提供此信息。为了确认这一点,您可以在同一个自动化帐户中运行以下PowerShell Runbook:

(gcm New-AzureStorageContext).OutputType.Type.Assembly.FullName
(gcm Backup-AzureRmApiManagement).Parameters.StorageContext.ParameterType.Assembly.FullName

如果它们实际指向不同的程序集,则可能需要将所有Azure模块的匹配版本导入AutomationAccount。此脚本可以提供帮助:https://github.com/azureautomation/runbooks/blob/master/Utility/ARM/Update-ModulesInAutomationToLatestVersion.ps1