【问题标题】:Assigning a public ip address to an existing nic in Azure using powershell使用 powershell 将公共 IP 地址分配给 Azure 中的现有网卡
【发布时间】:2023-03-29 10:36:02
【问题描述】:

使用 Azure CLI,可以创建一个公共 IP 地址并将其分配给现有的网卡,例如

在给定的资源组和区域中创建公共 ip

azure network public-ip create -g myresourcegroup -a Dynamic -l westus mypublicipname

将在上一步中创建的 pip 分配给现有的 nic

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 属性!有谁知道这是否应该工作?

【问题讨论】:

    标签: powershell azure networking command-line-interface nic


    【解决方案1】:

    感谢 AzureCAT 的 Tim Wieman (MSFT) 提供的解决方案!基本上你需要将新创建的 pip 分配给 nic 的 PublicIPAddress 属性,然后运行 ​​Set-AzureRmNetworkInterface 命令,如下所示:

        $nic.IpConfigurations[0].PublicIpAddress = $pip 
        Set-AzureRmNetworkInterface -NetworkInterface $nic
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-22
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      • 2021-05-02
      • 2013-09-30
      • 1970-01-01
      相关资源
      最近更新 更多