Created
June 12, 2015 13:28
-
-
Save ploegert/58c446f06444b90386b9 to your computer and use it in GitHub Desktop.
Azure VPN Tunnel Diagnostics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Write-Log | |
| { | |
| param( | |
| [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] | |
| [AllowEmptyString()] | |
| [string] | |
| $Message | |
| ) | |
| Write-Verbose -Verbose ("[{0:s}] {1}`r`n" -f (get-date), $Message) | |
| } | |
| # Authenticate to Azure with Azure AD credentials | |
| Write-Log "Authenticating to your Azure account" | |
| Add-AzureAccount | |
| # Select Azure Subscription | |
| $subscriptionName = (Get-AzureSubscription).SubscriptionName | Out-GridView -Title "Select Azure Subscription" -PassThru | |
| Select-AzureSubscription -SubscriptionName $subscriptionName | |
| #select storage | |
| Write-Log "Listing available Storage Accounts:" | |
| $storageAccountName = (Get-AzureStorageAccount).StorageAccountName | Out-GridView -Title "Select Azure Storage Account" -PassThru | |
| $storageAccountKey = (Get-AzureStorageKey -StorageAccountName $storageAccountName).Primary | |
| $storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey | |
| #select VNET | |
| Write-Log "Listing available Virtual Networks (having Gateways):" | |
| $azureVNet = (Get-AzureVNetSite | Where GatewayProfile -ne $null ).Name | Out-GridView -Title "Select Azure VNet" -PassThru | |
| #Get info around what the vnet contains: | |
| Write-log "Listing the Local Networks on the selected virtual network" | |
| $azureLocalSite = ((Get-AzureVNetSite -VNetName $azureVNet).GatewaySites | Select-Object -Property Name, VpnGatewayAddress | Out-GridView -Title "Select Azure target Local Network" -PassThru).Name | |
| #select duration | |
| #[int]$duration=Read-Host "`n Select Duration (seconds with 300 max)" | |
| #If (!($duration -gt 0 -and $duration -le 300)){ Write-Log "`n FAILED: Invalid Duration`n" -fore red;Exit } | |
| $captureDuration = 60 | |
| #Connect the network | |
| write-log "Resettingi the Gateway connection...This might take up to 2 minutes" | |
| Set-AzureVNetGateway -Connect –VnetName $azureVNet –LocalNetworkSiteName $azureLocalSite | |
| # Start capturing diagnostic logs - up to 300 seconds | |
| $StartDiags = Start-AzureVNetGatewayDiagnostics -VNetName $azureVNet -StorageContext $storageContext -CaptureDurationInSeconds $captureDuration | |
| If ($StartDiags.Status -eq "Successful") | |
| { Write-Log "`tSuccessfully started tracing" -fore green } | |
| Else | |
| { Write-Log "`tFAILED: $($StartDiags.Error)`n" -fore red; break } | |
| timeout 123 | |
| # Wait for diagnostics capturing to complete | |
| Write-Log "`n Waiting $duration seconds" | |
| Sleep -Seconds $captureDuration | |
| # Save diagnostics log locally | |
| $logUrl = (Get-AzureVNetGatewayDiagnostics -VNetName $azureVNet).DiagnosticsUrl | |
| $logContent = (Invoke-WebRequest -Uri $logUrl).RawContent | |
| $logContent | Out-File -FilePath vpnlog.txt | |
| #============================================================================== | |
| #Get information about what the current status of the gatway is | |
| Get-VNetGateway –VnetName $azureVNet | |
| #Get the Information about the gateway | |
| Get-AzureVNetGateway -VNetName $azureVNet | |
| Get-AzureVNetGatewayIPsecParameters -VNetName $azureVNet -LocalNetworkSiteName $azureLocalSite | |
| #Get info around what the vnet contains: | |
| Get-AzureVNetSite -VNetName $azureVNet | |
| #============================================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment