This document provides examples and considerations for using Azure PowerShell cmdlets to manage VPN client connections to Azure Virtual Network Gateways, with a focus on capacity-related scenarios.
Azure VPN Gateway enables secure, cross-premises connectivity. Managing VPN client connections involves configuring and monitoring these connections to ensure optimal performance and availability.
Before you begin, ensure you have the following:
You can install the Azure PowerShell module using:
Install-Module -Name Az -AllowClobber -Scope CurrentUserAnd connect to your Azure account with:
Connect-AzAccountThe Get-AzVpnClientConnection cmdlet retrieves information about VPN client connections to an Azure Virtual Network Gateway. This is a crucial cmdlet for monitoring and understanding current connection status, which can inform capacity planning.
Get-AzVpnClientConnection
    [-GatewayName <String>]
    [-ResourceGroupName <String>]
    [-SubscriptionId <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]| Name | Description | Required | 
|---|---|---|
| -GatewayName | The name of the Virtual Network Gateway. | No (if -ResourceGroupNameis provided and there's only one gateway in the RG) | 
| -ResourceGroupName | The name of the resource group. | No (if -GatewayNameis provided and there's only one gateway in the RG) | 
| -SubscriptionId | The ID of the subscription. | No | 
Here are some common examples demonstrating how to use the Get-AzVpnClientConnection cmdlet.
Retrieves all active VPN client connections for a Virtual Network Gateway named 'MyVpnGateway' in the resource group 'MyResourceGroup'.
Get-AzVpnClientConnection -ResourceGroupName "MyResourceGroup" -GatewayName "MyVpnGateway"This example shows how to get connection details and then potentially filter them further. For instance, you might want to see connections from specific IP addresses or users, though Get-AzVpnClientConnection primarily provides aggregated status.
To get more granular details, you'd often need to look at Network Watcher or logs.
$connections = Get-AzVpnClientConnection -ResourceGroupName "MyResourceGroup" -GatewayName "MyVpnGateway"
$connections | Where-Object { $_.ConnectionStatus -eq "Connected" }A common capacity-related task is to know the number of active connections. This example counts them.
$connectedCount = (Get-AzVpnClientConnection -ResourceGroupName "MyResourceGroup" -GatewayName "MyVpnGateway").Count
Write-Host "Number of active VPN client connections: $connectedCount"If you manage multiple VPN gateways within a resource group, you can retrieve connections from all of them.
Get-AzVirtualNetworkGateway -ResourceGroupName "MyResourceGroup" | ForEach-Object {
    $gatewayName = $_.Name
    Write-Host "--- Connections for Gateway: $gatewayName ---"
    Get-AzVpnClientConnection -ResourceGroupName "MyResourceGroup" -GatewayName $gatewayName
}Understanding the capacity limits of your Azure VPN Gateway is crucial for ensuring reliable VPN client connectivity. The Get-AzVpnClientConnection cmdlet helps you monitor current usage against these limits.
Get-AzVpnClientConnection periodically to track the number of connections over time.Get-AzVpnClientConnection cmdlet primarily shows the number of established client connections. It does not directly provide detailed per-client bandwidth usage. For detailed throughput monitoring, consider using Azure Monitor metrics for the VPN Gateway, which offer insights into aggregate ingress/egress data.
            If you consistently approach your gateway's capacity limits, you may need to scale up:
For more comprehensive information on Azure VPN Gateway, client connectivity, and capacity management, please refer to the following official Microsoft documentation: