Azure Automation PowerShell Workflow error Cannot bind parameter


You may find this error when you are creating a VM from Azure Automation by using PowerShell Workflow.
Error Details:

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 14/01/2016 14:05:49, Error: Add-AzureProvisioningConfig : Cannot bind parameter 'VM'. Cannot convert the  
"Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM" value of type
"Deserialized.Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM" to type
"Microsoft.WindowsAzure.Commands.ServiceManagement.Model.IPersistentVM".
At Test-Cred:24 char:24
+
+ CategoryInfo : InvalidArgument: (:) [Add-AzureProvisioningConfig], ParameterBindingException
+ FullyQualifiedErrorId :
CannotConvertArgumentNoMessage,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.AddAzureProvisioningConfigCommand
14/01/2016 14:05:49, Error: Set-AzureSubnet : Cannot bind parameter 'VM'. Cannot convert the
"Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM" value of type
"Deserialized.Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM" to type
"Microsoft.WindowsAzure.Commands.ServiceManagement.Model.IPersistentVM".
At Test-Cred:25 char:25
+
+ CategoryInfo : InvalidArgument: (:) [Set-AzureSubnet], ParameterBindingException
+ FullyQualifiedErrorId :
CannotConvertArgumentNoMessage,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.SetAzureSubnetCommand
14/01/2016 14:05:49, Error: New-AzureVM : Cannot bind parameter 'VMs'. Cannot convert value
"Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM" to type
"Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM". Error: "Cannot convert the
"Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM" value of type
"Deserialized.Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM" to type
"Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM"."
At Test-Cred:26 char:26
+
+ CategoryInfo : InvalidArgument: (:) [New-AzureVM], ParameterBindingException
+ FullyQualifiedErrorId :
CannotConvertArgumentNoMessage,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewAzureVMCommand

You may find it wired that the failing script may works as normal PowerShell rather than PowerShell Workflow. The above error is getting when I try to use VM object as a parameter. To solve the problem, you just need to wrap the script into a InlineScript keyword, such as:

1
2
3
4
InlineScript
{
#Paste your script here
}

Behind the scene, the reason is PowerShell workflow uses deserialized formats for objects to implement its checkpoints(a feature that allow you to start from the point of failure as opposed to start all of the way from beginning.). However, normal PowerShell script don’t have checkpoints, so it uses serialized format for object. Therefore, when you implement PowerShell script into PowerShell workflow, it doesn’ recognized the serialized format.