2

我正在使用静态(保留)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 不能为空或为空。

我试过用单引号

-Password $password | Set-AzureSubnet 'FrontEndSubnet'

但同样的结果。可能吗?

4

1 回答 1

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"   
于 2015-01-21T19:53:49.947 回答