How does one convert PSVirtualMachineObjects?

Viewed 1031

I'm trying to deploy Azure VM's thru a workflow so it could be done in parallel. The code works fine outside of a workflow. But getting this error when trying to do it thru a workflow.

I'm importing the VM parameters thru a csv file. Are there additional considerations for deploying Azure VM's thru a Workflow?

Workflow Deploy-VMs {
    $cred1= New-Object System.Management.Automation.PSCredential "User",$(ConvertTo-SecureString "Password" -asplaintext -force)
    $b=Import-Csv Y:\NLG\vms1.csv -Verbose|? type -eq 'VM'
    foreach ($c in $b) {
        AzureRM.Resources\Login-AzureRmAccount -Credential $cred1 -SubscriptionId subscription id
        $nic = New-AzureRmNetworkInterface -Name $c.Name -ResourceGroupName nlg -Location $c.Location -SubnetId $c.SubnetID 
        $cred= New-Object System.Management.Automation.PSCredential "nladmin",$(ConvertTo-SecureString $c.Password -asplaintext -force)
        $vmConfig = New-AzureRmVMConfig -VMName $c.Name -VMSize "Standard_D1" 
        $vmConfig = Set-AzureRmVMOperatingSystem -VM $vmConfig  -Windows -ComputerName $c.Name -Credential $cred 
        $vmConfig = Set-AzureRmVMSourceImage -VM $vmConfig -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2012-R2-Datacenter-smalldisk" -Version "latest" 
        $vmConfig = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id
        $vmConfig = Set-AzureRmVMOSDisk -VM $vmConfig -Name $c.Name -CreateOption FromImage
        New-AzureRmVM -ResourceGroupName $c.RG -Location $c.Location -VM $vmConfig
    }
}

and getting this error

Cannot bind parameter 'VM'. Cannot convert value "Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine" to type "Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine". Error: "Cannot convert the "Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine" value of type "Deserialized.Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine" to type "Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine"." + CategoryInfo : InvalidArgument: (:) [Set-AzureRmVMOperatingSystem], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.Compute.SetAzureVMOperatingSystemCommand + PSComputerName : [localhost]

1 Answers
Related