Skip to content

Commit 3a69ee4

Browse files
author
Michael Bender
committed
Updates to code for readability and usage
1 parent e06208e commit 3a69ee4

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

articles/virtual-network-manager/create-virtual-network-manager-powershell.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ Set-AzContext -Subscription <subscription name or id>
4848

4949
Install the latest *Az.Network* Azure PowerShell module using this command:
5050

51-
```azurepowershell-interactive
51+
```azurepowershell
5252
Install-Module -Name Az.Network -RequiredVersion 5.3.0
5353
```
5454
## Create a resource group
5555

5656
Before you can create an Azure Virtual Network Manager, you have to create a resource group to host the Network Manager. Create a resource group with [New-AzResourceGroup](/powershell/module/az.Resources/New-azResourceGroup). This example creates a resource group named **vnm-learn-eastus-001ResourceGroup** in the **WestUS** location.
5757

58-
```azurepowershell-interactive
58+
```azurepowershell
5959
6060
$location = "East US"
6161
$rg = @{
@@ -70,7 +70,7 @@ New-AzResourceGroup @rg
7070

7171
Define the scope and access type for the Azure Virtual Network Manager instance with [New-AzNetworkManagerScope](/powershell/module/az.network/new-aznetworkmanagerscope) This example defines a scope with a single subscription and sets the access type to **Connectivity**. Replace **<subscription id>** with the subscription ID of the subscription you want to manage with Azure Virtual Network Manager.
7272

73-
```azurepowershell-interactive
73+
```azurepowershell
7474
7575
Import-Module -Name Az.Network -RequiredVersion "5.3.0"
7676
@@ -87,7 +87,7 @@ $scope = New-AzNetworkManagerScope -Subscription $subGroup
8787

8888
Create the Virtual Network Manager with [New-AzNetworkManager](/powershell/module/az.network/new-aznetworkmanager). This example creates an Azure Virtual Network Manager named **vnm-learn-eastus-001** in the East Us location.
8989

90-
```azurepowershell-interactive
90+
```azurepowershell
9191
$avnm = @{
9292
Name = 'vnm-learn-eastus-001'
9393
ResourceGroupName = $rg.Name
@@ -102,7 +102,7 @@ $networkmanager = New-AzNetworkManager @avnm
102102

103103
Create three virtual networks with [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork). This example creates virtual networks named **vnet-learn-prod-eastus-001**, **vnet-learn-prod-eastus-002** and **vnet-learn-test-eastus-003** in the **East Us** location. If you already have virtual networks you want create a mesh network with, you can skip to the next section.
104104

105-
```azurepowershell-interactive
105+
```azurepowershell
106106
$vnet001 = @{
107107
Name = 'vnet-learn-prod-eastus-001'
108108
ResourceGroupName = $rg.Name
@@ -133,7 +133,7 @@ $vnet_learn_test_eastus_003 = New-AzVirtualNetwork @vnet003
133133

134134
To complete the configuration of the virtual networks, create a subnet configuration named **default** with [Add-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/add-azvirtualnetworksubnetconfig) with a subnet address prefix of **/24**. Then, use [Set-AzVirtualNetwork](/powershell/module/az.network/set-azvirtualnetwork) to apply the subnet configuration to the virtual network.
135135

136-
```azurepowershell-interactive
136+
```azurepowershell
137137
$subnet_vnet001 = @{
138138
Name = 'default'
139139
VirtualNetwork = $vnet_learn_prod_eastus_001
@@ -162,7 +162,7 @@ $vnet_learn_test_eastus_003 | Set-AzVirtualNetwork
162162
## Create a network group
163163
Virtual Network Manager applies configurations to groups of VNets by placing them in network groups. Create a network group with [New-AzNetworkManagerGroup](/powershell/module/az.network/new-aznetworkmanagergroup). This example creates a network group named **ng-learn-prod-eastus-001** in the **East Us** location.
164164

165-
```azurepowershell-interactive
165+
```azurepowershell
166166
$ng = @{
167167
Name = 'ng-learn-prod-eastus-001'
168168
ResourceGroupName = $rg.Name
@@ -183,15 +183,15 @@ In this task, you add the static members **vnet-learn-prod-eastus-001** and **vn
183183
> [!NOTE]
184184
> Static members must have a network group scoped unique name. It's recommended to use a consistent hash of the virtual network ID. This is an approach using the ARM Templates uniqueString() implementation.
185185
186-
```azurepowershell-interactive
186+
```azurepowershell
187187
function Get-UniqueString ([string]$id, $length=13)
188188
{
189189
$hashArray = (new-object System.Security.Cryptography.SHA512Managed).ComputeHash($id.ToCharArray())
190190
-join ($hashArray[1..$length] | ForEach-Object { [char]($_ % 26 + [byte][char]'a') })
191191
}
192192
```
193193

194-
```azurepowershell-interactive
194+
```azurepowershell
195195
$sm_vnet001 = @{
196196
Name = Get-UniqueString $vnet_learn_prod_eastus_001.Id
197197
ResourceGroupName = $rg.Name
@@ -202,7 +202,7 @@ $sm_vnet001 = @{
202202
$sm_vnet001 = New-AzNetworkManagerStaticMember @sm_vnet001
203203
```
204204

205-
```azurepowershell-interactive
205+
```azurepowershell
206206
$sm_vnet002 = @{
207207
Name = Get-UniqueString $vnet_learn_prod_eastus_002.Id
208208
ResourceGroupName = $rg.Name
@@ -223,7 +223,7 @@ Using [Azure Policy](concept-azure-policy-integration.md), you define a conditio
223223
> [!NOTE]
224224
> It is recommended to scope all of your conditionals to only scan for type `Microsoft.Network/virtualNetworks` for efficiency.
225225
226-
```azurepowershell-interactive
226+
```azurepowershell
227227
$conditionalMembership = '{
228228
"if": {
229229
"allOf": [
@@ -248,7 +248,7 @@ Using [Azure Policy](concept-azure-policy-integration.md), you define a conditio
248248
249249
1. Create the Azure Policy definition using the conditional statement defined in the last step using [New-AzPolicyDefinition](/powershell/module/az.resources/new-azpolicydefinition). In this example, the policy definition name is prefixed with **poldef-learn-prod-** and suffixed with a unique string generated from a consistent hash the network group ID. Policy resources must have a scope unique name.
250250

251-
```azurepowershell-interactive
251+
```azurepowershell
252252
function Get-UniqueString ([string]$id, $length=13)
253253
{
254254
$hashArray = (new-object System.Security.Cryptography.SHA512Managed).ComputeHash($id.ToCharArray())
@@ -258,7 +258,7 @@ Using [Azure Policy](concept-azure-policy-integration.md), you define a conditio
258258
$UniqueString = Get-UniqueString $ng.Id
259259
```
260260
261-
```azurepowershell-interactive
261+
```azurepowershell
262262
$polDef = @{
263263
Name = "poldef-learn-prod-"+$UniqueString
264264
Mode = 'Microsoft.Network.Data'
@@ -270,7 +270,7 @@ Using [Azure Policy](concept-azure-policy-integration.md), you define a conditio
270270
271271
1. Assign the policy definition at a scope within your network managers scope for it to begin taking effect.
272272
273-
```azurepowershell-interactive
273+
```azurepowershell
274274
$polAssign = @{
275275
Name = "polassign-learn-prod-"+$UniqueString
276276
PolicyDefinition = $policyDefinition
@@ -285,7 +285,7 @@ In this task, you create a connectivity configuration with the network group **n
285285
286286
1. Create a connectivity group item.
287287
288-
```azurepowershell-interactive
288+
```azurepowershell
289289
$gi = @{
290290
NetworkGroupId = $ng.Id
291291
}
@@ -294,14 +294,14 @@ In this task, you create a connectivity configuration with the network group **n
294294
295295
1. Create a configuration group and add connectivity group item to it.
296296
297-
```azurepowershell-interactive
297+
```azurepowershell
298298
[System.Collections.Generic.List[Microsoft.Azure.Commands.Network.Models.NetworkManager.PSNetworkManagerConnectivityGroupItem]]$configGroup = @()
299299
$configGroup.Add($groupItem)
300300
```
301301
302302
1. Create the connectivity configuration with the configuration group.
303303
304-
```azurepowershell-interactive
304+
```azurepowershell
305305
$config = @{
306306
Name = 'cc-learn-prod-eastus-001'
307307
ResourceGroupName = $rg.Name
@@ -316,7 +316,7 @@ In this task, you create a connectivity configuration with the network group **n
316316
317317
Commit the configuration to the target regions with Deploy-AzNetworkManagerCommit. This triggers your configuration to begin taking effect.
318318
319-
```azurepowershell-interactive
319+
```azurepowershell
320320
[System.Collections.Generic.List[string]]$configIds = @()
321321
$configIds.add($connectivityconfig.id)
322322
[System.Collections.Generic.List[string]]$target = @()
@@ -342,7 +342,7 @@ If you no longer need the Azure Virtual Network Manager, you need to make sure a
342342

343343
1. Remove the connectivity deployment by deploying an empty configuration with Deploy-AzNetworkManagerCommit.
344344

345-
```azurepowershell-interactive
345+
```azurepowershell
346346
[System.Collections.Generic.List[string]]$configIds = @()
347347
[System.Collections.Generic.List[string]]$target = @()
348348
$target.Add("westus")
@@ -358,14 +358,14 @@ If you no longer need the Azure Virtual Network Manager, you need to make sure a
358358
359359
1. Remove the connectivity configuration with Remove-AzNetworkManagerConnectivityConfiguration
360360
361-
```azurepowershell-interactive
361+
```azurepowershell
362362
363363
Remove-AzNetworkManagerConnectivityConfiguration -Name $connectivityconfig.Name -ResourceGroupName $rg.Name -NetworkManagerName $networkManager.Name
364364
365365
```
366366
2. Remove the policy resources with Remove-AzPolicy*
367367
368-
```azurepowershell-interactive
368+
```azurepowershell
369369
370370
Remove-AzPolicyAssignment -Name $policyAssignment.Name
371371
Remove-AzPolicyAssignment -Name $policyDefinition.Name
@@ -374,19 +374,19 @@ If you no longer need the Azure Virtual Network Manager, you need to make sure a
374374
375375
3. Remove the network group with Remove-AzNetworkManagerGroup.
376376
377-
```azurepowershell-interactive
377+
```azurepowershell
378378
Remove-AzNetworkManagerGroup -Name $ng.Name -ResourceGroupName $rg.Name -NetworkManagerName $networkManager.Name
379379
```
380380
381381
4. Delete the network manager instance with Remove-AzNetworkManager.
382382
383-
```azurepowershell-interactive
383+
```azurepowershell
384384
Remove-AzNetworkManager -name $networkManager.Name -ResourceGroupName $rg.Name
385385
```
386386
387387
5. If you no longer need the resource created, delete the resource group with [Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup).
388388
389-
```azurepowershell-interactive
389+
```azurepowershell
390390
Remove-AzResourceGroup -Name $rg.Name -Force
391391
```
392392

0 commit comments

Comments
 (0)