0

I have an ARM VM with a public IP. I want to detach/dissociate this public IP after my test. I can see there is an option using azure portal-

enter image description here

I want to do the same thing using azure powershell. I tried finding azure cmdlets related to public IP but couldn't achieve it. If someone can give me some clue how this can be done ?

Aatif Akhter
  • 2,126
  • 1
  • 25
  • 46

2 Answers2

3

You need to get the Network Interface object and remove the Ip Address Id from it and push changes back to Azure.

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

Many Azure cmdlets work in similar fashion.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
1

Not sure if this PowerShell method ever worked.

The null assignment gives the error

 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

This is what I have done as a workaround.

$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
shiraj
  • 11
  • 2