Skip to content

Commit 4ce0b96

Browse files
committed
completed first pass on powershell
1 parent 8001e68 commit 4ce0b96

File tree

1 file changed

+150
-81
lines changed

1 file changed

+150
-81
lines changed

articles/virtual-network/tutorial-create-route-table-portal.md

Lines changed: 150 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -105,36 +105,51 @@ A **DMZ** and **Private** subnet are needed for this tutorial. The **DMZ** subne
105105
Create a resource group with [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup). The following example creates a resource group named *test-rg* for all resources created in this article.
106106

107107
```azurepowershell-interactive
108-
New-AzResourceGroup -ResourceGroupName test-rg -Location EastUS
108+
$rg = @{
109+
ResourceGroupName = "test-rg"
110+
Location = "EastUS2"
111+
}
112+
113+
New-AzResourceGroup @rg
109114
```
110115

111116
Create a virtual network with [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork). The following example creates a virtual network named *vnet-1* with the address prefix *10.0.0.0/16*.
112117

113118
```azurepowershell-interactive
114-
$virtualNetwork = New-AzVirtualNetwork `
115-
-ResourceGroupName test-rg `
116-
-Location EastUS `
117-
-Name vnet-1 `
118-
-AddressPrefix 10.0.0.0/16
119+
$vnet = @{
120+
ResourceGroupName = "test-rg"
121+
Location = "EastUS2"
122+
Name = "vnet-1"
123+
AddressPrefix = "10.0.0.0/16"
124+
}
125+
126+
$virtualNetwork = New-AzVirtualNetwork @vnet
119127
```
120128

121129
Create three subnets by creating three subnet configurations with [New-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/new-azvirtualnetworksubnetconfig). The following example creates three subnet configurations for *Public*, *Private*, and *DMZ* subnets:
122130

123131
```azurepowershell-interactive
124-
$subnetConfigPublic = Add-AzVirtualNetworkSubnetConfig `
125-
-Name subnet-public `
126-
-AddressPrefix 10.0.0.0/24 `
127-
-VirtualNetwork $virtualNetwork
128-
129-
$subnetConfigPrivate = Add-AzVirtualNetworkSubnetConfig `
130-
-Name subnet-private `
131-
-AddressPrefix 10.0.1.0/24 `
132-
-VirtualNetwork $virtualNetwork
133-
134-
$subnetConfigDmz = Add-AzVirtualNetworkSubnetConfig `
135-
-Name subnet-dmz `
136-
-AddressPrefix 10.0.2.0/24 `
137-
-VirtualNetwork $virtualNetwork
132+
$subnetConfigPublicParams = @{
133+
Name = "subnet-1"
134+
AddressPrefix = "10.0.0.0/24"
135+
VirtualNetwork = $virtualNetwork
136+
}
137+
138+
$subnetConfigPrivateParams = @{
139+
Name = "subnet-private"
140+
AddressPrefix = "10.0.1.0/24"
141+
VirtualNetwork = $virtualNetwork
142+
}
143+
144+
$subnetConfigDmzParams = @{
145+
Name = "subnet-dmz"
146+
AddressPrefix = "10.0.2.0/24"
147+
VirtualNetwork = $virtualNetwork
148+
}
149+
150+
$subnetConfigPublic = Add-AzVirtualNetworkSubnetConfig @subnetConfigPublicParams
151+
$subnetConfigPrivate = Add-AzVirtualNetworkSubnetConfig @subnetConfigPrivateParams
152+
$subnetConfigDmz = Add-AzVirtualNetworkSubnetConfig @subnetConfigDmzParams
138153
```
139154

140155
Write the subnet configurations to the virtual network with [Set-AzVirtualNetwork](/powershell/module/az.network/Set-azVirtualNetwork), which creates the subnets in the virtual network:
@@ -201,26 +216,31 @@ Network virtual appliances (NVAs) are virtual machines that help with network fu
201216

202217
### Create a network interface
203218

204-
Before creating a network interface, you have to retrieve the virtual network Id with [Get-AzVirtualNetwork](/powershell/module/az.network/get-azvirtualnetwork), then the subnet Id with [Get-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/get-azvirtualnetworksubnetconfig). Create a network interface with [New-AzNetworkInterface](/powershell/module/az.network/new-aznetworkinterface) in the *DMZ* subnet with IP forwarding enabled:
219+
Before creating a network interface, you have to retrieve the virtual network Id with [Get-AzVirtualNetwork](/powershell/module/az.network/get-azvirtualnetwork), then the subnet Id with [Get-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/get-azvirtualnetworksubnetconfig). Create a network interface with [New-AzNetworkInterface](/powershell/module/az.network/new-aznetworkinterface) in the *DMZ* subnet:
205220

206221
```azurepowershell-interactive
207222
# Retrieve the virtual network object into a variable.
208-
$virtualNetwork=Get-AzVirtualNetwork `
209-
-Name vnet-1 `
210-
-ResourceGroupName test-rg
223+
$vnetParams = @{
224+
Name = "vnet-1"
225+
ResourceGroupName = "test-rg"
226+
}
227+
$virtualNetwork = Get-AzVirtualNetwork @vnetParams
211228
212229
# Retrieve the subnet configuration into a variable.
213-
$subnetConfigDmz = Get-AzVirtualNetworkSubnetConfig `
214-
-Name subnet-dmz `
215-
-VirtualNetwork $virtualNetwork
230+
$subnetConfigParams = @{
231+
Name = "subnet-dmz"
232+
VirtualNetwork = $virtualNetwork
233+
}
234+
$subnetConfigDmz = Get-AzVirtualNetworkSubnetConfig @subnetConfigParams
216235
217236
# Create the network interface.
218-
$nic = New-AzNetworkInterface `
219-
-ResourceGroupName test-rg `
220-
-Location eastus2 `
221-
-Name 'vm-nva' `
222-
-SubnetId $subnetConfigDmz.Id `
223-
-EnableIPForwarding
237+
$nicParams = @{
238+
ResourceGroupName = "test-rg"
239+
Location = "eastus2"
240+
Name = "vm-nva"
241+
SubnetId = $subnetConfigDmz.Id
242+
}
243+
$nic = New-AzNetworkInterface @nicParams
224244
```
225245

226246
### Create a VM
@@ -229,31 +249,48 @@ To create a VM and attach an existing network interface to it, you must first cr
229249

230250
```azurepowershell-interactive
231251
# Create a credential object.
232-
$cred = Get-Credential -Message "Enter a username and password for the VM."
252+
$credParams = @{
253+
Message = "Enter a username and password for the VM."
254+
}
255+
$cred = Get-Credential @credParams
233256
234257
# Create a VM configuration.
235-
$vmConfig = New-AzVMConfig `
236-
-VMName 'vm-nva' `
237-
-VMSize Standard_DS2 | `
238-
Set-AzVMOperatingSystem -Windows `
239-
-ComputerName 'vm-nva' `
240-
-Credential $cred | `
241-
Set-AzVMSourceImage `
242-
-PublisherName MicrosoftWindowsServer `
243-
-Offer WindowsServer `
244-
-Skus 2016-Datacenter `
245-
-Version latest | `
246-
Add-AzVMNetworkInterface -Id $nic.Id
258+
$vmConfigParams = @{
259+
VMName = 'vm-nva'
260+
VMSize = 'Standard_DS2'
261+
}
262+
$vmConfig = New-AzVMConfig @vmConfigParams
263+
264+
$osParams = @{
265+
Windows = $true
266+
ComputerName = 'vm-nva'
267+
Credential = $cred
268+
}
269+
$vmConfig = $vmConfig | Set-AzVMOperatingSystem @osParams
270+
271+
$imageParams = @{
272+
PublisherName = 'Canonical'
273+
Offer = '0001-com-ubuntu-server-focal'
274+
Skus = '24_04-lts'
275+
Version = 'latest'
276+
}
277+
$vmConfig = $vmConfig | Set-AzVMSourceImage @imageParams
278+
279+
$nicParams = @{
280+
Id = $nic.Id
281+
}
282+
$vmConfig = $vmConfig | Add-AzVMNetworkInterface @nicParams
247283
```
248284

249285
Create the VM using the VM configuration with [New-AzVM](/powershell/module/az.compute/new-azvm). The following example creates a VM named *vm-nva*.
250286

251287
```azurepowershell-interactive
252-
$vmNva = New-AzVM `
253-
-ResourceGroupName test-rg `
254-
-Location eastus2 `
255-
-VM $vmConfig `
256-
-AsJob
288+
$vmNvaParams = @{
289+
ResourceGroupName = "test-rg"
290+
Location = "eastus2"
291+
VM = $vmConfig
292+
}
293+
$vmNva = New-AzVM @vmNvaParams -AsJob
257294
```
258295

259296
The `-AsJob` option creates the VM in the background, so you can continue to the next step.
@@ -365,26 +402,30 @@ The public virtual machine is used to simulate a machine in the public internet.
365402
Create a VM in the *subnet-public* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm). The following example creates a VM named *myVmPublic* in the *subnet-public* subnet of the *vnet-1* virtual network.
366403

367404
```azurepowershell-interactive
368-
New-AzVm `
369-
-ResourceGroupName "test-rg" `
370-
-Location "eastus2" `
371-
-VirtualNetworkName "vnet-1" `
372-
-SubnetName "subnet-public" `
373-
-ImageName "Win2016Datacenter" `
374-
-Name "vm-public `
375-
-AsJob
405+
$vmPublicParams = @{
406+
ResourceGroupName = "test-rg"
407+
Location = "eastus2"
408+
VirtualNetworkName = "vnet-1"
409+
SubnetName = "subnet-public"
410+
ImageName = "Canonical:0001-com-ubuntu-server-focal:24_04-lts:latest"
411+
Name = "vm-public"
412+
AsJob = $true
413+
}
414+
New-AzVm @vmPublicParams
376415
```
377416

378417
Create a VM in the *subnet-private* subnet.
379418

380419
```azurepowershell-interactive
381-
New-AzVm `
382-
-ResourceGroupName "test-rg" `
383-
-Location "eastus2" `
384-
-VirtualNetworkName "vnet-1" `
385-
-SubnetName "subnet-private" `
386-
-ImageName "Win2016Datacenter" `
387-
-Name "vm-private"
420+
$vmPrivateParams = @{
421+
ResourceGroupName = "test-rg"
422+
Location = "eastus2"
423+
VirtualNetworkName = "vnet-1"
424+
SubnetName = "subnet-private"
425+
ImageName = "Canonical:0001-com-ubuntu-server-focal:24_04-lts:latest"
426+
Name = "vm-private"
427+
}
428+
New-AzVm @vmPrivateParams
388429
```
389430

390431
The VM takes a few minutes to create. Don't continue with the next step until the VM is created and Azure returns output to PowerShell.
@@ -423,6 +464,24 @@ In this section, you turn on IP forwarding for the network interface of the **vm
423464

424465
### [PowerShell](#tab/powershell)
425466

467+
Enable IP forwarding for the network interface of the **vm-nva** virtual machine with [Set-AzNetworkInterface](/powershell/module/az.network/set-aznetworkinterface). The following example enables IP forwarding for the network interface named *vm-nva313*.
468+
469+
```azurepowershell-interactive
470+
$nicParams = @{
471+
Name = "vm-nva313"
472+
ResourceGroupName = "test-rg"
473+
}
474+
475+
$nic = Get-AzNetworkInterface @nicParams
476+
$nic.EnableIPForwarding = $true
477+
478+
$setNicParams = @{
479+
InputObject = $nic
480+
}
481+
482+
Set-AzNetworkInterface @setNicParams
483+
```
484+
426485
### [CLI](#tab/cli)
427486

428487
---
@@ -510,7 +569,7 @@ In this section, create a route in the route table that you created in the previ
510569
| Destination type | Select **IP Addresses**. |
511570
| Destination IP addresses/CIDR ranges | Enter **10.0.2.0/24**. |
512571
| Next hop type | Select **Virtual appliance**. |
513-
| Next hop address | Enter **10.0.3.4**. </br> **_This is the IP address you of vm-nva you created in the earlier steps._**. |
572+
| Next hop address | Enter **10.0.3.4**. </br> **_This is the IP address of the vm-nva you created in the earlier steps._**. |
514573

515574
:::image type="content" source="./media/tutorial-create-route-table-portal/add-route.png" alt-text="Screenshot of route creation in route table.":::
516575

@@ -534,24 +593,31 @@ In this section, create a route in the route table that you created in the previ
534593
Create a route table with [New-AzRouteTable](/powershell/module/az.network/new-azroutetable). The following example creates a route table named *route-table-public*.
535594

536595
```azurepowershell-interactive
537-
$routeTablePublic = New-AzRouteTable `
538-
-Name 'route-table-public' `
539-
-ResourceGroupName test-rg `
540-
-location eastus2
596+
$routeTableParams = @{
597+
Name = 'route-table-public'
598+
ResourceGroupName = 'test-rg'
599+
Location = 'eastus2'
600+
}
601+
$routeTablePublic = New-AzRouteTable @routeTableParams
541602
```
542603

543604
Create a route by retrieving the route table object with [Get-AzRouteTable](/powershell/module/az.network/get-azroutetable), create a route with [Add-AzRouteConfig](/powershell/module/az.network/add-azrouteconfig), then write the route configuration to the route table with [Set-AzRouteTable](/powershell/module/az.network/set-azroutetable).
544605

545606
```azurepowershell-interactive
546-
Get-AzRouteTable `
547-
-ResourceGroupName "test-rg" `
548-
-Name "route-table-public" `
549-
| Add-AzRouteConfig `
550-
-Name "to-private-subnet" `
551-
-AddressPrefix 10.0.1.0/24 `
552-
-NextHopType "VirtualAppliance" `
553-
-NextHopIpAddress 10.0.2.4 `
554-
| Set-AzRouteTable
607+
$routeTableParams = @{
608+
ResourceGroupName = "test-rg"
609+
Name = "route-table-public"
610+
}
611+
612+
$routeConfigParams = @{
613+
Name = "to-private-subnet"
614+
AddressPrefix = "10.0.1.0/24"
615+
NextHopType = "VirtualAppliance"
616+
NextHopIpAddress = "10.0.2.4"
617+
}
618+
619+
$routeTable = Get-AzRouteTable @routeTableParams
620+
$routeTable | Add-AzRouteConfig @routeConfigParams | Set-AzRouteTable
555621
```
556622

557623
### [CLI](#tab/cli)
@@ -641,7 +707,10 @@ Test routing of network traffic from **vm-public** to **vm-private**. Test routi
641707
When no longer needed, use [Remove-AzResourcegroup](/powershell/module/az.resources/remove-azresourcegroup) to remove the resource group and all of the resources it contains.
642708
643709
```azurepowershell-interactive
644-
Remove-AzResourceGroup -Name test-rg -Force
710+
$rgParams = @{
711+
Name = "test-rg"
712+
}
713+
Remove-AzResourceGroup @rgParams -Force
645714
```
646715
647716
### [CLI](#tab/cli)

0 commit comments

Comments
 (0)