Skip to content

Commit 48df301

Browse files
authored
Update New-AzNetworkInterface.md
Removed reference to the manual subnet entry and added code to allow retrieval of subnetID via PowerShell from Virtual Network. This would be a best practice rather than hard-coding subnet ID entry.
1 parent 5371a38 commit 48df301

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Network/Network/help/New-AzNetworkInterface.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ created automatically using the name IPConfiguration1.
7070

7171
### Example 2: Create an Azure network interface using an IP configuration object
7272
```
73-
PS C:\>$IPconfig = New-AzNetworkInterfaceIpConfig -Name "IPConfig1" -PrivateIpAddressVersion IPv4 -PrivateIpAddress "10.0.1.10" -SubnetId "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/ResourceGroup1/providers/Microsoft.Network/virtualNetworks/VirtualNetwork1/subnets/Subnet1"
73+
PS C:\>$Subnet = Get-AzVirtualNetwork -name "VirtualNetwork1" -ResourceGroupName "ResourceGroup1"
74+
PS C:\>$IPconfig = New-AzNetworkInterfaceIpConfig -Name "IPConfig1" -PrivateIpAddressVersion IPv4 -PrivateIpAddress "10.0.1.10" -SubnetId $Subnet.subnets[0].id
7475
PS C:\> New-AzNetworkInterface -Name "NetworkInterface1" -ResourceGroupName "ResourceGroup1" -Location "centralus" -IpConfiguration $IPconfig
7576
```
7677

7778
This example creates a new network interface using an IP configuration object. The IP configuration
7879
object specifies a static private IPv4 address.
79-
The first command creates a network interface IP configuration named IPConfig1 and stores the
80+
The first command retrieves an existing specified virtual network used to assign the subnet in the second command.
81+
The second command creates a network interface IP configuration named IPConfig1 and stores the
8082
configuration in the variable named $IPconfig.
81-
The second command creates a network interface named NetworkInterface1 that uses the network
83+
The third command creates a network interface named NetworkInterface1 that uses the network
8284
interface IP configuration stored in the variable named $IPconfig.
8385

8486
## PARAMETERS

0 commit comments

Comments
 (0)