如何分离/分离ARM VM的公共IP

时间:2017-09-25 06:15:25

标签: azure azure-virtual-machine azure-powershell

我有一台带有公共IP的ARM VM。我想在测试后分离/分离这个公共知识产权。我可以看到有一个使用azure portal-

的选项

enter image description here

我想用azure powershell做同样的事情。我尝试找到与公共IP相关的天蓝色cmdlet,但无法实现它。 如果有人能给我一些线索如何做到这一点?

2 个答案:

答案 0 :(得分:2)

您需要获取网络接口对象并从中删除IP地址ID并将更改推送回Azure。

$nic = Get-AzureRmNetworkInterface -Name bla -ResourceGroup blabla
$nic.IpConfigurations.publicipaddress.id = $null
Set-AzureRmNetworkInterface -NetworkInterface $nic

许多Azure cmdlet以类似的方式工作。

答案 1 :(得分:1)

不确定这个 PowerShell 方法是否有效。

空赋值给出错误

 PS C:\Users\xxxxxxxxxx>  $nic.IpConfigurations.publicipaddress.id=$null
 The property 'id' cannot be found on this object. Verify that the property 
 exists and can be set.
 At line:1 char:2
 +  $nic.IpConfigurations.publicipaddress.id=$null
 +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
 + FullyQualifiedErrorId : PropertyAssignmentException

这是我所做的解决方法。

$nic = Get-AzNetworkInterface -Name $pip.NICName -ResourceGroup `
        $pip.ResourceGrou
$count= $nic.IpConfigurations.Name.Count
$i=0
while ($i -le ($count-1)){   
     $nic.IpConfigurations[$i].publicipaddress.id=$null
      $i++}
Set-AzNetworkInterface -NetworkInterface $nic