About This Page
This page is part of the Azure documentation. It contains code examples and configuration instructions for working with Azure services.
Bias Analysis
Bias Types:
⚠️
powershell_heavy
⚠️
missing_linux_example
⚠️
windows_tools
⚠️
windows_first
Summary:
The documentation provides detailed instructions for performing the NSG relocation using the Azure Portal and Azure PowerShell. All CLI-based automation examples are exclusively in PowerShell, with no mention of Azure CLI (az) or Bash scripting, which are cross-platform and preferred by many Linux users. Additionally, references to tools like 'notepad' and the use of PowerShell cmdlets reinforce a Windows-centric approach. There are no Linux-specific or cross-platform command-line examples, and PowerShell is presented before any mention of alternatives.
Recommendations:
- Add equivalent instructions and examples using Azure CLI (az) commands, which are cross-platform and commonly used on Linux and macOS.
- Include Bash scripting examples for template editing and deployment, or at least mention compatible editors (e.g., vim, nano, code) instead of only 'notepad'.
- Where PowerShell is referenced, clarify that Azure CLI is also supported and provide links or tabs for both.
- Ensure that all automation steps (export, edit, deploy, cleanup) have both PowerShell and Azure CLI/Bash equivalents.
- Avoid assuming the user's environment is Windows; use neutral language and tool references where possible.
Create pull request
Flagged Code Snippets
1. Obtain the resource ID of the NSG you want to move to the target region and place it in a variable using [Get-AzNetworkSecurityGroup](/powershell/module/az.network/get-aznetworksecuritygroup):
"resources": [
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-06-01",
"name": "[parameters('networkSecurityGroups_myVM1_nsg_name')]",
"location": "<target-region>",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "2c846acf-58c8-416d-be97-ccd00a4ccd78",
"securityRules": [
{
"name": "RDP",
"etag": "W/\"c630c458-6b52-4202-8fd7-172b7ab49cf5\"",
"properties": {
"provisioningState": "Succeeded",
"protocol": "TCP",
"sourcePortRange": "*",
"destinationPortRange": "3389",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 300,
"direction": "Inbound",
"sourcePortRanges": [],
"destinationPortRanges": [],
"sourceAddressPrefixes": [],
"destinationAddressPrefixes": []
}
}
]
}
}
1. Export the source NSG to a .json file into the directory where you execute the command [Export-AzResourceGroup](/powershell/module/az.resources/export-azresourcegroup):
1. To verify the resources were created in the target region, use [Get-AzResourceGroup](/powershell/module/az.resources/get-azresourcegroup) and [Get-AzNetworkSecurityGroup](/powershell/module/az.network/get-aznetworksecuritygroup):
1. To obtain region location codes, you can use the Azure PowerShell cmdlet [Get-AzLocation](/powershell/module/az.resources/get-azlocation) by running the following command:
1. Save the **\<resource-group-name>.json** file.
---
## Redeploy
### [Portal](#tab/azure-portal)
1. Select **BASICS** > **Subscription** to choose the subscription where the target NSG will be deployed.
1. Select **BASICS** > **Resource group** to choose the resource group where the target NSG will be deployed. You can click **Create new** to create a new resource group for the target NSG. Ensure the name isn't the same as the source resource group of the existing NSG.
1. Select **BASICS** > **Location** is set to the target location where you wish for the NSG to be deployed.
1. Verify under **SETTINGS** that the name matches the name that you entered in the parameters editor above.
1. Check the box under **TERMS AND CONDITIONS**.
1. Select the **Purchase** button to deploy the target network security group.
### [PowerShell](#tab/azure-powershell)
1. Create a resource group in the target region for the target NSG to be deployed using [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup):
1. Deploy the edited **\<resource-group-name>.json** file to the resource group created in the previous step using [New-AzResourceGroupDeployment](/powershell/module/az.resources/new-azresourcegroupdeployment):
---
## Discard
### [Portal](#tab/azure-portal)
If you wish to discard the target NSG, delete the resource group that contains the target NSG. To do so, select the resource group from your dashboard in the portal and select **Delete** at the top of the overview page.
### [PowerShell](#tab/azure-powershell)
After the deployment, if you wish to start over or discard the NSG in the target, delete the resource group that was created in the target and the moved NSG will be deleted. To remove the resource group, use [Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup):
---
## Clean up
### [Portal](#tab/azure-portal)
To commit the changes and complete the move of the NSG, delete the source NSG or resource group. To do so, select the network security group or resource group from your dashboard in the portal and select **Delete** at the top of each page.
### [PowerShell](#tab/azure-powershell)
To commit the changes and complete the move of the NSG, delete the source NSG or resource group, use [Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup) or [Remove-AzNetworkSecurityGroup](/powershell/module/az.network/remove-aznetworksecuritygroup):