从Microsoft Azure中的CLI使用映像(.VHD)创建Windows VM

时间:2016-05-31 15:06:15

标签: azure

我在使用Azure的新门户创建Image然后从该映像创建VM时遇到问题。 虽然使用了一些帮助 " https://azure.microsoft.com/en-in/documentation/articles/virtual-machines-windows-capture-image/#comments"我可以使用CLI创建映像,但是从该映像创建VM时,几乎没有命令会抛出错误。需要帮助

如链接文件中所示:

$vnet = New-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName -Location $location -AddressPrefix $vnetAddressPrefix -Subnet $subnetconfig

我的版本:

$vnet = New-AzureRmVirtualNetwork -Name myvirtualnetwork -ResourceGroupName my_Resource_Group -Location southus -AddressPrefix 10.0.0.0/** -Subnet 10.0.0.0/**

** - >一些数字

以下是我在power shell中遇到的错误:

New-AzureRmVirtualNetwork : Cannot bind parameter 'Subnet'. Cannot convert the "10.0.0.0/**" value of type
"System.String" to type "Microsoft.Azure.Commands.Network.Models.PSSubnet".
At line:1 char:153
+ ... 0.0/16 -Subnet 10.0.0.0/**
+                    ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-AzureRmVirtualNetwork], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.Network.NewAzureVirtualNetworkCommand

1 个答案:

答案 0 :(得分:0)

参数 -Subnet 需要一个类型为“ Microsoft.Azure.Commands.Network.Models.PSSubnet ”的变量。也就是说,不是直接将子网作为字符串传递,而是必须传递一个对象。

尝试(确保相应地更改参数):

$VnetName = "MyVNET"
$AddressPrefix = "10.0.0.0/24"
$SubnetName = "Subnet-1"
$SubnetPrefix = "10.0.0.0/27"
$ResouceGroup = "MyRG"
$Location = "eastus"

$subnetconfig = New-AzureRmVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $SubnetPrefix

$vnet = New-AzureRmVirtualNetwork -Name $VnetName -ResourceGroupName $ResouceGroup -Location $Location -AddressPrefix $AddressPrefix -Subnet $subnetconfig

顺便说一下:

“southus”不是有效位置。使用Get-AzureRmLocation列出所有可用的

“10.0.0.0 / **”不是有效的前缀。您必须定义要使用的正确网段。

相关问题