# VNET Resource Group and Name
$rgName = ‘your resource name’
$vnetGwName = "your GW name"
$timestamp = get-date -uFormat "%d%m%y@%H%M%S"
# Details of existing Storage Account that will be used to collect the logs
$storageAccountName = "storage account name"
$storageAccountKey = ‘storage account key’
$captureDuration = 60
$storageContainer = "vpnlogs"
$logDownloadPath = "D:\vpnlogs (create the folder first)"
$Logfilename = "VPNDiagLog_" + $vnetGwName + "_" + $timestamp + ".txt"
# Set Storage Context and VNET Gateway ID
$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
# NOTE: This is an Azure Service Manager cmdlet and so no AzureRM on this one. AzureRM will not work as we don’t get the gatewayID with it.
$vnetGws = Get-AzureVirtualNetworkGateway
# Added check for only provisioned gateways as older deleted gateways of same name can also appear in results and capture will fail
$vnetGwId = ($vnetGws | ? GatewayName -eq $vnetGwName | ? state -EQ "provisioned").GatewayID
# Start Azure VNET Gateway logging
Start-AzureVirtualNetworkGatewayDiagnostics `
-GatewayId $vnetGwId `
-CaptureDurationInSeconds $captureDuration `
-StorageContext $storageContext `
-ContainerName $storageContainer
# Optional – Test VNET gateway connection to another server across the tunnel
# Only use this if you are connected to the local network you are connecting to FROM Azure. Otherwise create some traffic across the link from on prem.
# Test-NetConnection -ComputerName 10.0.0.4 -CommonTCPPort RDP
# Wait for diagnostics capturing to complete
Sleep -Seconds $captureDuration
# Step 6 – Download VNET gateway diagnostics log
$logUrl = ( Get-AzureVirtualNetworkGatewayDiagnostics -GatewayId $vnetGwId).DiagnosticsUrl
$logContent = (Invoke-WebRequest -Uri $logUrl).RawContent
$logContent | Out-File -FilePath $logDownloadPath\$Logfilename
无法直接查看日志,但我们可以下载 VPN 网关的诊断日志。为了存储日志,您应该在 VPN 网关的同一资源组中添加存储帐户和存储容器。下面是使用 PowerShell 为 VPN 网关配置诊断日志的示例 (ARM):
这个脚本需要一一执行。
有关诊断日志的更多信息,请参阅链接。