Skip to main content
Jorge Bernhardt Jorge Bernhardt
  1. Posts/

How to install the Network Watcher VM extension from the Command Line

·652 words·4 mins· 100 views · 5 likes ·
Azure CLI Azure PowerShell Connect-AzAccount Get-AzSubscription

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>

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.

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:

Get-AzSubscription
Select-AzSubscription -Subscription "My Subscription"

Once you set your default subscription, you’re ready to start.

Set the variables>

Set the variables #

Here, we define the characteristics of our environment and the resource’s properties.

$resourceGroupName = "RG-DEMO-WE"
$location = "westeurope"
$vmName = "VM-DEMO-WE"
Install Network Watcher VM extension>

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.

Set-AzVMExtension `
    -Name "networkWatcherAgent" `
    -Publisher "Microsoft.Azure.NetworkWatcher" `
    -Type "NetworkWatcherAgentWindows" `
    -TypeHandlerVersion 1.4 `
    -VMName $vmName `
    -ResourceGroupName $resourceGroupName `
    -Location $location
List installed VM extensions>

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 `
    -VMName $vmName `
    -ResourceGroupName $resourceGroupName |
    Select-Object VMName, Name, Location,ExtensionType, ProvisioningState `
    | format-table

Get-AzVMExtension

Remove Network Watcher VM Extension>

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.

Remove-AzVMExtension `
    -VMName $vmName `
    -ResourceGroupName $resourceGroupName `
    -Name "networkWatcherAgent" `
    -force
Azure CLI Workaround>

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.

resourceGroupName="RG-DEMO-WE"
vmName="VM-DEMO-WE"
Install Network Watcher VM extension>

Install Network Watcher VM extension #

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

az vm extension set \
--vm-name $vmName \
--resource-group $resourceGroupName \
--publisher Microsoft.Azure.NetworkWatcher \
--version 1.4 \
--name NetworkWatcherAgentWindows \
--extension-instance-name networkWatcherAgent

Network Watcher extension

List installed VM extensions>

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.

az vm extension list \
--vm-name $vmName \
--resource-group $resourceGroupName \
--output table
Remove Network Watcher VM Extension>

Remove Network Watcher VM Extension #

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

az vm extension delete \
--vm-name $vmName \
--resource-group $resourceGroupName \
--name NetworkWatcherAgent

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.