I have a graphical runbook which backups up an instance of Azure API Management to Azure storage. I have used this technique in Powershell many times but thought i'd try it with a graphical runbook.
When I get the storage context from the New-AzureStorageContext and try to use it in the Backup-AzureRmApiManagement I get the following error:
Here is how I hook the storage context from the previous activity to my backup activity:
People suggest that the context gets serialized and that I should use an InlineScript but I can't get this to work.
Here is what I think is the serialized context:
Would be great to get this to work.
Assuming that this is a Graphical (not Graphical PowerShell Workflow) runbook, there should be no serialization issues here.
Most likely, the problem is caused by a mismatch of module versions in your Automation Account. The error message indicates that New-AzureStorageContext expects a parameter of type AzureStorageContext, and it receives a value of type AzureStorageContext. However, different module versions can refer to types defined in different assemblies, and the value cannot be converted to another type automatically. For example, New-AzureStorageContext from Azure.Storage (version A) may return an AzureStorageContext object incompatible with the type expected by Backup-AzureRmApiManagement from AzureRM.ApiManagement (version B). Unfortunately, the error message does not provide this information. In order to confirm that, you can run the following PowerShell runbook in the same Automation Account:
(gcm New-AzureStorageContext).OutputType.Type.Assembly.FullName
(gcm Backup-AzureRmApiManagement).Parameters.StorageContext.ParameterType.Assembly.FullName
If they in fact point to different assemblies, you may need to import the matching versions of all Azure modules into your AutomationAccount. This script can help: https://github.com/azureautomation/runbooks/blob/master/Utility/ARM/Update-ModulesInAutomationToLatestVersion.ps1