Skip to content

Instantly share code, notes, and snippets.

@rwaal
Created March 9, 2020 20:34
Show Gist options
  • Save rwaal/869e6dee63541b064128b389bdb0e68b to your computer and use it in GitHub Desktop.
Save rwaal/869e6dee63541b064128b389bdb0e68b to your computer and use it in GitHub Desktop.
Associate Azure Public IP to an existing Network Interface using Powershell
$pip = New-AzPublicIpAddress -Name 'MyPublicIpName' -ResourceGroupName 'MyResourceGroupName' -Sku 'Basic' -AllocationMethod 'Dynamic' -Location 'West Europe'
$vnet = Get-AzVirtualNetwork -Name 'MyVnetName' -ResourceGroupName 'MyResourceGroupName'
$subnet = Get-AzVirtualNetworkSubnetConfig -Name 'MySubnetName' -VirtualNetwork $vnet
$nic = Get-AzNetworkInterface -Name 'MyNicName' -ResourceGroupName 'MyResourceGroupName'
$ipconfig = New-AzNetworkInterfaceIpConfig -Name 'MyIpConfigName' -Subnet $subnet -PublicIpAddress $pip
$nic | Add-AzNetworkInterfaceIpConfig -Name $ipconfigName -Subnet $subnet -PublicIpAddress $pip
$nic | Set-AzNetworkInterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment