Today I want to talk to you about Azure Network Watcher, a handy tool to diagnose and repair the state of the IaaS network. Once this tool is enabled in our region, we can use various tools to check and repair the communication between the different resources of our virtual network, such as virtual machines, virtual networks, application gateways, load, etc.
Network Watcher has two categories of tools:
- Monitoring tools
- Diagnostic tools
In this post, I want to show you how to enable or disable Network Watcher for an Azure region using PowerShell and Azure CLI.
Prerequisites
- This tutorial assumes that you already have a Microsoft Azure account configured.
Important: When you create or update a virtual network in your subscription, Network Watcher will be enabled automatically in your Virtual Network’s region.
Azure PowerShell Workaround
If you want to know how to install the PowerShell Azure module on your machine, check out this link.
The simplest way to get started is to sign in interactively at the command line.
1 2 3 | Connect-AzAccount |
This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account.
If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:
1 2 3 4 | Get-AzSubscription Select-AzSubscription -Subscription "My Subscription" |
Once you set your default subscription, you’re ready to start.
Set the variables
Here, we define the characteristics of our environment and the resource’s properties.
1 2 3 4 | $resourceGroupName = "RG-DEMO-WE" $location = "westeurope" |
Enable Network Watcher
To enable Azure Network watcher on your region, use the New-AzNetworkWatcher cmdlet with the following syntax.
1 2 3 4 5 | New-AzNetworkWatcher -Name "NetworkWatcher_westeurope" ` -ResourceGroupName $resourceGroupName ` -Location $location |
Disable Network Watcher
if you want to disable Azure Network watcher on your region, you should use the Remove-AzNetworkWatcher cmdlet with the following syntax.
1 2 3 | Get-AzNetworkWatcher -Name "NetworkWatcher_westeurope" | Remove-AzNetworkWatcher |
Azure CLI Workaround
In this case, we will use Azure Cloud Shell, a browser-based shell built into Azure Portal. This allows us to use the Azure command-line tools (Azure CLI and Azure PowerShell) directly from a browser. If you want to know more about Azure Cloud Shell, check out this link.
First, we define the characteristics of our environment and store the values in variables.
1 2 3 4 | resourceGroupName="RG-DEMO-NE" location="northeurope" |
Enable Network Watcher
To enable Network Watcher, run the following command.
1 2 3 4 5 | az network watcher configure --resource-group $resourceGroupName \ --locations $location \ --enabled true |
Disable Network Watcher
If you need to disable Azure Network watcher for any reason, use the following command.
1 2 3 4 5 6 | az network watcher configure --resource-group $resourceGroupName \ --locations $location \ --enabled false |
Thanks for reading my post. I hope you find it useful.
In a future article, I will show you How to install the Network Watcher VM extension using command-line tools.
For more information about Network Watcher, see this link:https://docs.microsoft.com/en-us/azure/network-watcher/