Last active
March 29, 2017 08:40
-
-
Save kagarlickij/2c8a6072720a1384bdff7dd27dd720e5 to your computer and use it in GitHub Desktop.
This file contains 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
<# | |
.NOTES | |
=========================================================================== | |
Created on: Jan 2017 | |
Created by: Dmitriy Kagarlickij | |
Contact: dmitriy@kagarlickij.com | |
=========================================================================== | |
.DESCRIPTION | |
This script should be executing with Administrator-level permissions | |
#> | |
$mainIfName = "Ethernet" | |
$vpnIfDescription = "TAP-Windows Adapter*" | |
$mainIfIndex = $((Get-NetAdapter | Where-Object {$_.Name -eq $mainIfName}).ifIndex) | |
$vpnIfIndex = $((Get-NetAdapter | Where-Object {$_.InterfaceDescription -like $vpnIfDescription}).ifIndex) | |
$mainIfMetric = $((Get-NetIPInterface | Where-Object {$_.ifIndex -eq $mainIfIndex -and $_.AddressFamily -eq 'IPv4'}).InterfaceMetric) | |
$vpnIfMetric = $((Get-NetIPInterface | Where-Object {$_.ifIndex -eq $vpnIfIndex -and $_.AddressFamily -eq 'IPv4'}).InterfaceMetric) | |
if ($vpnIfMetric -ge $mainIfMetric) { | |
Write-Output "VPN DNS will be fixed now" | |
Set-NetIPInterface -InterfaceIndex $vpnIfIndex -InterfaceMetric $($mainIfMetric-5) | |
$mainIfMetric = $((Get-NetIPInterface | Where-Object {$_.ifIndex -eq $mainIfIndex -and $_.AddressFamily -eq 'IPv4'}).InterfaceMetric) | |
$vpnIfMetric = $((Get-NetIPInterface | Where-Object {$_.ifIndex -eq $vpnIfIndex -and $_.AddressFamily -eq 'IPv4'}).InterfaceMetric) | |
if ($vpnIfMetric -lt $mainIfMetric) { | |
Write-Output "VPN DNS has been fixed successfully" | |
} else { | |
Write-Output "VPN DNS has been fixed with error" | |
} | |
} else { | |
Write-Output "VPN DNS is ok" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment