Azure,使用保留的IP地址创建VM,并将其放在用户子网中

时间:2015-01-17 00:27:10

标签: azure azure-powershell

我正在创建具有静态(保留)IP地址的VM

$adminUser = "*****"
$password = "*****"

$reservedIP = "myIP"

# VM Creation Details 
$vmName = "*****" 
$vmSize = "Small"
$serviceName = "*****"
$location = "West Europe"

$imageFamily = "Windows Server 2012 R2 Datacenter"
$imageName = Get-AzureVMImage |
                 where { $_.ImageFamily -eq $imageFamily } |
                 sort PublishedDate -Descending |
                 select -ExpandProperty ImageName -First 1 



# create reserved IP
New-AzureReservedIP – ReservedIPName $reservedIP –Label $reservedIP –Location $location


# Create a virtual machine configuration object 
$vm = New-AzureVMConfig -Name $vmName -InstanceSize $vmSize -ImageName $imageName |`
        Add-AzureProvisioningConfig -Windows `
                                    -AdminUsername $adminUser `
                                    -Password $password 


New-AzureVM -ServiceName $serviceName -Location $location `
            -VMs $vm `
            -ReservedIPName $reservedIP # Specify the reserved IP address for the external VIP

这里一切都好。

但我有网络"我的网络",还有子网,例如" FrontEndSubnet"。如何将vm放入此子网?我试着这样做

$vm2 = New-AzureVMConfig -Name $vmName -InstanceSize $vmSize -ImageName $imageName |`
        Add-AzureProvisioningConfig -Windows `
                                    -AdminUsername $adminUser `
                                    -Password $password | `
                                     Set-AzureSubnet "FrontEndSubnet"

New-AzureVM -ServiceName $serviceName -Location $location `
            -VMs $vm2 `
            -ReservedIPName $reservedIP # Specify the reserved IP address for the external VIP

但得到了

  

New-AzureVM:BadRequest:虚拟网络ID不能为null或   空。

我试过单引号

-Password $password | Set-AzureSubnet 'FrontEndSubnet'

但结果相同。有可能吗?

1 个答案:

答案 0 :(得分:0)

解决,像这个例子一样创建:

New-AzureReservedIP –ReservedIPName $reservedIP –Label $reservedIP –Location “West Europe”
Get-AzureReservedIP


# Create a virtual machine configuration object 
$vmcfg = New-AzureVMConfig -Name $vmName -InstanceSize $vmSize -ImageName $imageName -Label "WFE name" |`
            Set-AzureSubnet "FrontEndSubnet" | `
            Add-AzureProvisioningConfig -Windows -AdminUsername $adminUser -Password $password

Test-AzureName -Service $serviceName
# here will be False if servicename is free

New-AzureVM -ServiceName $serviceName -ReservedIPName $reservedIP -Location "West Europe" -VMs $vmcfg -VNetName "MyNetwork"