-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzureRM - Get VNET Gateway Logs.ps1
131 lines (93 loc) · 3.09 KB
/
AzureRM - Get VNET Gateway Logs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# STEP 1: Sign-in to Azure via Azure Resource Manager
Login-AzureRmAccount
# STEP 2: Select Azure Subscription
$subscriptionId =
( Get-AzureRmSubscription |
Out-GridView `
-Title "Select an Azure Subscription ..." `
-PassThru
).SubscriptionId
Select-AzureRmSubscription `
-SubscriptionId $subscriptionId
# STEP 3: If needed, register ARM core resource providers
Register-AzureRmResourceProvider `
-ProviderNamespace Microsoft.Compute
Register-AzureRmResourceProvider `
-ProviderNamespace Microsoft.Storage
Register-AzureRmResourceProvider `
-ProviderNamespace Microsoft.Network
Get-AzureRmResourceProvider |
Select-Object `
-Property ProviderNamespace `
-ExpandProperty ResourceTypes
# STEP 4: Select Azure Resource Group in which existing VNET is provisioned
$rgName =
( Get-AzureRmResourceGroup |
Out-GridView `
-Title "Select an Azure Resource Group ..." `
-PassThru
).ResourceGroupName
# STEP 5: Select Azure VNET gateway on which to start diagnostics logging
$vnetGwName =
( Get-AzureRmVirtualNetworkGateway `
-ResourceGroupName $rgName
).Name |
Out-GridView `
-Title "Select an Azure VNET Gateway ..." `
-PassThru
# STEP 6: Select Azure Storage Account on which to send logs
$storageAccountName =
( Get-AzureRmStorageAccount `
-ResourceGroupName $rgName
).StorageAccountName |
Out-GridView `
-Title "Select an Azure Storage Account ..." `
-PassThru
# STEP 7: Get Key for Azure Storage Account
$storageAccountKey =
( Get-AzureRmStorageAccountKey `
-Name $storageAccountName `
-ResourceGroupName $rgName
)[0].Value
# STEP 8: Sign-in to Azure via Azure Service Management
Add-AzureAccount
# STEP 9: Select same Azure subscription via Azure Service Management
Select-AzureSubscription `
-SubscriptionId $subscriptionId
# STEP 10: Set Storage Context for storing logs
$storageContext =
New-AzureStorageContext `
-StorageAccountName $storageAccountName `
-StorageAccountKey $storageAccountKey
# STEP 11: Get Gateway ID for VNET Gateway
$vnetGws = Get-AzureVirtualNetworkGateway
$vnetGwId =
( $vnetGws |
? GatewayName -eq $vnetGwName
).GatewayId
# STEP 12: Start Azure VNET Gateway logging
$captureDuration = 60
$storageContainer = "vpnlogs"
Start-AzureVirtualNetworkGatewayDiagnostics `
-GatewayId $vnetGwId `
-CaptureDurationInSeconds $captureDuration `
-StorageContext $storageContext `
-ContainerName $storageContainer
# STEP 13: Test VNET gateway connection to another server across the tunnel
Test-NetConnection `
-ComputerName 10.0.0.4 `
-CommonTCPPort RDP
# STEP 14: Wait for diagnostics capturing to complete
Sleep -Seconds $captureDuration
# STEP 15: Download VNET gateway diagnostics log
$logUrl =
( Get-AzureVirtualNetworkGatewayDiagnostics `
-GatewayId $vnetGwId
).DiagnosticsUrl
$logContent =
( Invoke-WebRequest `
-Uri $logUrl
).RawContent
$logContent |
Out-File `
-FilePath vpnlog.txt