2017-08-11 21 views
5

मैं एक वर्कफ़्लो के माध्यम से एज़ूर वीएम को तैनात करने की कोशिश कर रहा हूं ताकि यह समानांतर में किया जा सके। कोड वर्कफ़्लो के बाहर ठीक काम करता है। लेकिन वर्कफ़्लो के माध्यम से ऐसा करने का प्रयास करते समय यह त्रुटि प्राप्त हो रही है।कोई PSVirtualMachineObjects को कैसे परिवर्तित करता है?

मैं एक सीएसवी फ़ाइल के माध्यम से वीएम पैरामीटर आयात कर रहा हूं। क्या एज़ूर वीएम को वर्कफ़्लो के माध्यम से तैनात करने के लिए अतिरिक्त विचार हैं?

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 
    } 
} 

और इस त्रुटि

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]

+0

क्या आपने पावरहेल मॉड्यूल को अपडेट करने का प्रयास किया था? – 4c74356b41

+0

हां। मदद नहीं करता है। मैं पावरहेल v5.1 –

+1

का उपयोग कर रहा हूं, मैं अपनी प्रयोगशाला में परीक्षण करता हूं। मुझे आपके साथ एक ही परिणाम मिलते हैं। शायद आप समानांतर में वीएम बनाने के लिए [example] (https://blogs.inframon.com/2016/09/deploy-in-parallel-multiple-azure-virtual-machines-powershell-workflow-script/) का उपयोग कर सकते हैं। –

उत्तर

1

असंगत cmdlets के लिए इनलाइन स्क्रिप्ट का उपयोग कर हल हो रही।

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 -Parallel ($c in $b) { 
     AzureRM.Resources\Login-AzureRmAccount -Credential $cred1 -SubscriptionId c2d7e81b-ed6a-4de9-a4cd-36e679ec4259 
     $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) 
     InlineScript { 
      $vmConfig = New-AzureRmVMConfig -VMName $using:c.Name -VMSize "Standard_D1" 
      $vmConfig = Set-AzureRmVMOperatingSystem -VM $vmConfig -Windows -ComputerName $using:c.Name -Credential $using:cred 
      $vmConfig = Set-AzureRmVMSourceImage -VM $vmConfig -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2012-R2-Datacenter-smalldisk" -Version "latest" 
      $vmConfig = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $using:nic.Id 
      $vmConfig = Set-AzureRmVMOSDisk -VM $vmConfig -Name $using:c.Name -CreateOption FromImage 
      New-AzureRmVM -ResourceGroupName $using:c.RG -Location $using:c.Location -VM $vmConfig 
     } 
    } 
} 
संबंधित मुद्दे

 संबंधित मुद्दे