none
Exception calling AzureProvisioningConfig RRS feed

  • Question

  • I have a Powershell Script that runs fine in PowerShell. I put the same script into a runbook and I get an exception. Here is the exception and code snippet:

    Exception
    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". (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". (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".))

    Code snippet

    Write-Output "New-AzureMVConfig"
      $vm = New-AzureVMConfig `
             -Name $MachineName `
             -InstanceSize Medium `
             -ImageName $ImageName `
             -MediaLocation "$StorageAccountContainer$MachineName.vhd" `
             -AvailabilitySetName $AvailabilitySetName `
             -DiskLabel "OS"
       if ($vm -eq $null)
       {
        Write-Output "It was null"
       }
                else
                {
                    Write-Output "vm is $vm"
                }
       Write-Output "Add-AzureProvisioningConfig"
       $vm | Add-AzureProvisioningConfig `
              -WindowsDomain `
              -AdminUserName $LocalAdminUser `
              -Password $LocalAdminPassword `
              -DisableAutomaticUpdates `
              -Domain $DomainName `
              -JoinDomain $FQDN `
              -DomainUserName $DomainJoinUser `
              -DomainPassword $DomainJoinPassword
              
       Write-Output "Set-AzureSubnet"
       $vm | Set-AzureSubnet `
           -SubnetNames $SubnetName -VM $vm
       Write-Output "New-AzureVM"
       
       $vm | New-AzureVM `
          -VMs $CloudServiceName -VNetName $VirtualNetworkName -Verbose



    • Edited by baparker Thursday, June 5, 2014 3:29 PM
    Thursday, June 5, 2014 3:27 PM

Answers

  • Hi,

    PowerShell Workflow is different than PowerShell in that it stores complex types in deserialized form. Primitives will stay as primitives, but complex types are converted to property bags.

    In your specific example, New-AzureVMConfig returns an object of type Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM. In PS Workflow it would return an object of type Deserialized.Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM, which has all the same properties as Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM, but none of the methods. Add-AzureProvisioningConfig expects a value of type Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM for the VM parameter. Since Deserialized.Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM is not the same type as Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM, you get a type mismatch error.

    The solution when one cmdlet produces a complex object, and another cmdlet takes in that complex object as a parameter, is that you need to wrap these cmdlets together in an InlineScript. InlineScript is a PS Workflow activity that runs whatever is inside it in the context of PowerShell, rather than PowerShell Workflow.


    • Marked as answer by Joe Levy_ Thursday, June 5, 2014 10:41 PM
    Thursday, June 5, 2014 10:40 PM