使用 Azure CLI,可以创建公共(public) IP 地址并将其分配给现有的网卡,例如
在给定资源组和区域中创建公共(public) IP
azure network public-ip create -g myresourcegroup -a Dynamic -l westus mypublicipname
将上一步中创建的 pip 分配给现有网卡
azure network nic set -g myresourcegroup -p mypublicipname mynicname
但是类似的代码在 powershell 中不起作用,例如
创建新点(成功完成)
$pip = New-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $rgName -Location $locName -AllocationMethod Dynamic -Force
分配给现有网卡
$nic = Get-AzureRmNetworkInterface -ResourceGroupName $rgName -Name $nicName
$nic.IpConfigurations[0].PublicIpAddress = $pip.IpAddress
最后一行不起作用并引发以下错误:
The property 'Id' cannot be found on this object. Verify that the property exists and can be set.
At line:31 char:9
+ $nic.IpConfigurations[0].PublicIpAddress.Id = $pip.Id
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
虽然 PS ISE 中的智能感知确实显示了两者的 Id 属性!有谁知道这是否应该起作用?
最佳答案
感谢 AzureCAT 的 Tim Wieman (MSFT) 提供的解决方案!基本上,您需要将新创建的 pip 分配给 nic 的 PublicIPAddress 属性,然后运行 Set-AzureRmNetworkInterface 命令,如下所示:
$nic.IpConfigurations[0].PublicIpAddress = $pip
Set-AzureRmNetworkInterface -NetworkInterface $nic
关于powershell - 使用 powershell 将公共(public) IP 地址分配给 Azure 中的现有网卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34164282/