Skip to content

Commit 83c1965

Browse files
author
Michael Bender
committed
Updates to code for readability and usage
1 parent 62878e2 commit 83c1965

File tree

1 file changed

+92
-93
lines changed

1 file changed

+92
-93
lines changed

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

Lines changed: 92 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -178,133 +178,132 @@ Once your network group is created, you define a network group's membership by a
178178

179179
### Manually add membership
180180

181-
In this task, you manually add two virtual networks for your Mesh configuration to your network group using these steps:
182-
183-
1. Add the static member to the network group with the following commands:
184-
1. 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.
185-
186-
```azurepowershell-interactive
187-
function Get-UniqueString ([string]$id, $length=13)
188-
{
189-
$hashArray = (new-object System.Security.Cryptography.SHA512Managed).ComputeHash($id.ToCharArray())
190-
-join ($hashArray[1..$length] | ForEach-Object { [char]($_ % 26 + [byte][char]'a') })
191-
}
192-
```
193-
194-
```azurepowershell-interactive
195-
$smA = @{
196-
Name = Get-UniqueString $vnet_learn_prod_eastus_001.Id
197-
ResourceGroupName = $rg.Name
198-
NetworkGroupName = ng.Name
199-
NetworkManagerName = $networkManager.Name
200-
ResourceId = $vnet_learn_prod_eastus_001.Id
201-
}
202-
$statimemberA = New-AzNetworkManagerStaticMember @sm
203-
```
204-
205-
```azurepowershell-interactive
206-
$smB = @{
207-
Name = Get-UniqueString $vnet_learn_prod_eastus_002.Id
208-
ResourceGroupName = $rg.Name
209-
NetworkGroupName = ng.Name
210-
NetworkManagerName = $networkManager.Name
211-
ResourceId = $vnet_learn_prod_eastus_002.Id
212-
}
213-
$statimemberB = New-AzNetworkManagerStaticMember @sm
214-
```
181+
In this task, you add the static members **vnet-learn-prod-eastus-001** and **vnet-learn-prod-eastus-002** to the network group **ng-learn-prod-eastus-001** using [New-AzNetworkManagerStaticMember](/powershell/module/az.network/new-aznetworkmanagerstaticmember).
182+
183+
> [!NOTE]
184+
> 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.
185+
186+
```azurepowershell-interactive
187+
function Get-UniqueString ([string]$id, $length=13)
188+
{
189+
$hashArray = (new-object System.Security.Cryptography.SHA512Managed).ComputeHash($id.ToCharArray())
190+
-join ($hashArray[1..$length] | ForEach-Object { [char]($_ % 26 + [byte][char]'a') })
191+
}
192+
```
215193

216-
```azurepowershell-interactive
217-
$smC = @{
218-
Name = Get-UniqueString $virtualNetworkC.Id
219-
ResourceGroupName = $rg.Name
220-
NetworkGroupName = ng.Name
221-
NetworkManagerName = $networkManager.Name
222-
ResourceId = $virtualNetworkC.Id
223-
}
224-
$statimemberC = New-AzNetworkManagerStaticMember @sm
225-
```
194+
```azurepowershell-interactive
195+
$sm_vnet001 = @{
196+
Name = Get-UniqueString $vnet_learn_prod_eastus_001.Id
197+
ResourceGroupName = $rg.Name
198+
NetworkGroupName = $ng.Name
199+
NetworkManagerName = $networkManager.Name
200+
ResourceId = $vnet_learn_prod_eastus_001.Id
201+
}
202+
$sm_vnet001 = New-AzNetworkManagerStaticMember @sm_vnet001
203+
```
226204

205+
```azurepowershell-interactive
206+
$sm_vnet002 = @{
207+
Name = Get-UniqueString $vnet_learn_prod_eastus_002.Id
208+
ResourceGroupName = $rg.Name
209+
NetworkGroupName = $ng.Name
210+
NetworkManagerName = $networkManager.Name
211+
ResourceId = $vnet_learn_prod_eastus_002.Id
212+
}
213+
$sm_vnet002 = New-AzNetworkManagerStaticMember @sm_vnet002
214+
```
215+
227216
# [Azure Policy](#tab/azurepolicy)
228-
### Create Azure Policy for dynamic membership
229217

230-
Using [Azure Policy](concept-azure-policy-integration.md), you define a condition to dynamically add two virtual networks to your network group when the name of the virtual network includes **prod** using these steps:
218+
### Create a policy for dynamic membership
219+
220+
Using [Azure Policy](concept-azure-policy-integration.md), you define a condition to dynamically add two virtual networks to your network group when the name of the virtual network name includes **-prod** using these steps:
231221

232222
1. Define the conditional statement and store it in a variable.
233223
> [!NOTE]
234-
> It is recommended to scope all of your conditionals to only scan for type `Microsoft.Network/virtualNetwork` for efficiency.
235-
236-
```azurepowershell-interactive
237-
$conditionalMembership = '{
238-
"allof":[
239-
{
240-
"field": "type",
241-
"equals": "Microsoft.Network/virtualNetwork"
242-
}
243-
{
244-
"field": "name",
245-
"contains": "VNet"
246-
}
247-
]
248-
}'
249-
```
224+
> It is recommended to scope all of your conditionals to only scan for type `Microsoft.Network/virtualNetworks` for efficiency.
225+
226+
```azurepowershell-interactive
227+
$conditionalMembership = '{
228+
"if": {
229+
"allOf": [
230+
{
231+
"field": "type",
232+
"equals": "Microsoft.Network/virtualNetworks"
233+
},
234+
{
235+
"field": "name",
236+
"contains": "prod"
237+
}
238+
]
239+
},
240+
"then": {
241+
"effect": "addToNetworkGroup",
242+
"details": {
243+
"networkGroupId": "/subscriptions/dec492d3-4f4e-493b-aa47-7bdf2f96a6fc/resourceGroups/rg-learn-eastus-001/providers/Microsoft.Network/networkManagers/vnm-learn-eastus-001/networkGroups/ng-learn-prod-eastus-001"}
244+
},
245+
}'
246+
247+
```
250248
251-
1. Create the Azure Policy definition using the conditional statement defined in the last step using New-AzPolicyDefinition.
249+
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.
252250

253-
> [!IMPORTANT]
254-
> Policy resources must have a scope unique name. It is recommended to use a consistent hash of the network group. This is an approach using the ARM Templates uniqueString() implementation.
255-
256-
```azurepowershell-interactive
257-
function Get-UniqueString ([string]$id, $length=13)
258-
{
259-
$hashArray = (new-object System.Security.Cryptography.SHA512Managed).ComputeHash($id.ToCharArray())
260-
-join ($hashArray[1..$length] | ForEach-Object { [char]($_ % 26 + [byte][char]'a') })
261-
}
262-
```
263-
264-
```azurepowershell-interactive
265-
$defn = @{
266-
Name = Get-UniqueString ng.Id
267-
Mode = 'Microsoft.Network.Data'
268-
Policy = $conditionalMembership
269-
}
270-
271-
$policyDefinition = New-AzPolicyDefinition @defn
272-
```
251+
```azurepowershell-interactive
252+
function Get-UniqueString ([string]$id, $length=13)
253+
{
254+
$hashArray = (new-object System.Security.Cryptography.SHA512Managed).ComputeHash($id.ToCharArray())
255+
-join ($hashArray[1..$length] | ForEach-Object { [char]($_ % 26 + [byte][char]'a') })
256+
}
257+
258+
$UniqueString = Get-UniqueString $ng.Id
259+
```
260+
261+
```azurepowershell-interactive
262+
$polDef = @{
263+
Name = "poldef-learn-prod-"+$UniqueString
264+
Mode = 'Microsoft.Network.Data'
265+
Policy = $conditionalMembership
266+
}
267+
268+
$policyDefinition = New-AzPolicyDefinition @polDef
269+
```
273270
274271
1. Assign the policy definition at a scope within your network managers scope for it to begin taking effect.
275272
276273
```azurepowershell-interactive
277-
$assgn = @{
278-
Name = Get-UniqueString ng.Id
274+
$polAssign = @{
275+
Name = "polassign-learn-prod-"+$UniqueString
279276
PolicyDefinition = $policyDefinition
280277
}
281278
282-
$policyAssignment = New-AzPolicyAssignment @assgn
279+
$policyAssignment = New-AzPolicyAssignment @polAssign
283280
```
284281
---
285-
## Create a configuration
282+
## Create a connectivity configuration
283+
In this task, you create a connectivity configuration with the network group **ng-learn-prod-eastus-001** using [New-AzNetworkManagerConnectivityConfiguration](/powershell/module/az.network/new-aznetworkmanagerconnectivityconfiguration) and [New-AzNetworkManagerConnectivityGroupItem](/powershell/module/az.network/new-aznetworkmanagerconnectivitygroupitem).
284+
286285
287-
1. Create a connectivity group item to add a network group to with New-AzNetworkManagerConnectivityGroupItem.
286+
1. Create a connectivity group item.
288287
289288
```azurepowershell-interactive
290289
$gi = @{
291-
NetworkGroupId = ng.Id
290+
NetworkGroupId = $ng.Id
292291
}
293292
$groupItem = New-AzNetworkManagerConnectivityGroupItem @gi
294293
```
295294
296-
1. Create a configuration group and add the group item from the previous step.
295+
1. Create a configuration group and add connectivity group item to it.
297296
298297
```azurepowershell-interactive
299298
[System.Collections.Generic.List[Microsoft.Azure.Commands.Network.Models.PSNetworkManagerConnectivityGroupItem]]$configGroup = @()
300299
$configGroup.Add($groupItem)
301300
```
302301
303-
1. Create the connectivity configuration with New-AzNetworkManagerConnectivityConfiguration.
302+
1. Create the connectivity configuration with the configuration group.
304303
305304
```azurepowershell-interactive
306305
$config = @{
307-
Name = 'connectivityconfig'
306+
Name = 'cc-learn-prod-eastus-001'
308307
ResourceGroupName = $rg.Name
309308
NetworkManagerName = $networkManager.Name
310309
ConnectivityTopology = 'Mesh'
@@ -313,7 +312,7 @@ Using [Azure Policy](concept-azure-policy-integration.md), you define a conditio
313312
$connectivityconfig = New-AzNetworkManagerConnectivityConfiguration @config
314313
```
315314
316-
## Commit deployment
315+
### Commit deployment
317316
318317
Commit the configuration to the target regions with Deploy-AzNetworkManagerCommit. This triggers your configuration to begin taking effect.
319318

0 commit comments

Comments
 (0)