New-AzureVMConfig : A positional parameter cannot be found that accepts argument 'Add-AzureProvisioningConfig'

StackOverflow https://stackoverflow.com/questions/13947762

  •  10-12-2021
  •  | 
  •  

I'm new to powershell. I refered to http://msdn.microsoft.com/en-us/library/windowsazure/jj152815.aspx example 3. here is my cmd:

$myVM = New-AzureVMConfig -Name "MyVM2" -InstanceSize Extrasmall -ImageName (Get-AzureVMImage)[4].ImageName| Add-AzureProvisioningConfig -VM PersistentVMRole -Windows -Password "Password1!"| Add-AzureDataDisk -CreateNew -DiskSizeInGB 50 -DiskLabel "DataDisk50" -LUN 0

But I get the error here: New-AzureVMConfig : A positional parameter cannot be found that accepts argument 'Add-AzureProvisioningConfig'. At line:1 char:26 + $myVM = New-AzureVMConfig <<<< -Name "MyVM2" -InstanceSize Extrasmall -ImageName (Get-AzureVMImage)[4].ImageName| A dd-AzureProvisioningConfig -Windows -Password "Password1!"| Add-AzureDataDisk -CreateNew -DiskSizeInGB 50 -DiskLabel " DataDisk50" -LUN 0 + CategoryInfo : InvalidArgument: (:) [New-AzureVMConfig], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.WindowsAzure.Management.ServiceManagement.IaaS.New AzureVMConfigCommand

Please can anyone explain why does this example can't be run? I'm going to crazy!

有帮助吗?

解决方案

There's a couple of problems with this script:

  1. Unless you've set a default storage account (which the link doesn't) for your subscription you'll need to use -MediaLocation switch in the first CmdLet
  2. If you pipe the first CmdLet into second as you are you won't need the -VM switch which in your case references a string literal rather than $vm.

Some of the VM documentation can contain inconsistencies a much better reference point to get started is Michael Washam's blog http://michaelwasham.com or this may help you if you swap out the sql image for the one you're interested in http://blog.elastacloud.com/2012/06/30/tricks-with-iaas-and-sql-part-1-installing-sql-server-2012-vms-using-powershell/

其他提示

Try splitting the command over multiple lines, this will help you to pinpoint the actual issue:

$images = Get-AzureVMImage
$imageName = $images[4].ImageName
$vm = New-AzureVMConfig -Name "MyVM2" -InstanceSize Extrasmall -ImageName $imageName
Add-AzureProvisioningConfig -VM $vm -Windows -Password "Password1!"
Add-AzureDataDisk -VM $vm -CreateNew -DiskSizeInGB 50 -DiskLabel "DataDisk50" -LUN 0
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top