powershell - 使用 powershell 将公共(public) IP 地址分配给 Azure 中的现有网卡

标签 powershell azure networking command-line-interface nic

使用 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/

相关文章:

azure - 使用Azure Function .NET 5,如何下载数据?

java - Firebase 云函数更改超时

Docker Container 在混杂模式下的网络接口(interface)

azure - 在动态创建的 Web 应用服务中添加自定义域

java DatagramSocket接收数据 组播Socket发送数据

powershell - 从SCRATCH创建二维系统阵列

powershell - 使用 Powershell 4.0 更新计划任务操作参数

powershell - 如何指定哈希表的数据类型?

powershell - 使用文件和目录的函数的惯用参数类型

azure - 如何在 Azure(而不是 AWS 亚马逊)上构建无服务器网站