In a previous post, I showed you how to enable network watcher in your Azure region. Today I will show you how to install the Network Watcher VM extension on your virtual machines using PowerShell and Azure CLI.

This extension is required when you want to use most of the Network Watcher tools. If you use these tools from the portal, the extension is installed automatically. But if you’re going to automate the deployment of extensions in your virtual machines or use the Network Watcher tools from the command line, this post will be helpful for you.

Prerequisites

  • Network Watcher must be enabled in your region. If you want to know how to enable it, check out this link.

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.

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:

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.

Install Network Watcher VM extension

To install the Network Watcher extension on your virtual machine, you must use the Set-AzVMExtension cmdlet with the following syntax.

List installed VM extensions

To check the correct installation of the extension or, If you want to list the extensions installed in your virtual machine, you can use the Get-AzVMExtension cmdlet with the following syntax.

Get-AzVMExtension

Remove Network Watcher VM Extension

If you need to remove a VM extension for some reason, you can use the Remove-AzVMExtension cmdlet with the following syntax.

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.

Install Network Watcher VM extension

To install the network Watcher extension on your virtual machine, you should use the following commands.

Network Watcher extension

List installed VM extensions

To check the correct installation of the extension, or If you want to list the extensions installed in your virtual machine, you can use the following commands.

Remove Network Watcher VM Extension

If you need to remove a VM extension, you can use the following command.

Thanks for reading my post. I hope you find it useful.

I will show you how to use Network Watcher packet capture from the command line in a future post.

For more information about Network Watcher, see this link.