0
votes

I am fairly new to PowerShell so please forgive me if the question looks stupid.

I am trying to configure VPN Connections using PowerShell. With the help of PowerShell ISE, I have no trouble creating a VPN connection and configuring VPN specifics. However I also need to set the DNS server of this VPN to 8.8.8.8, a task of which none of the cmdlets in VpnClient module is capable. I figured that all the settings in "Networking" tab is not accessed by VpnClient module so I tried DnsClient, NetAdapter,NetTCPIP and NetConnection, but the commands in these module all need a parameter called either Name or InterfaceAlias.

I successfully changed the DNS Configuration of my Ethernet Adapter by Set-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses 8.8.8.8,8.8.4.4. However, if I give my vpn name to -InterfaceAlias option then PowerShell gives out an error, saying it cannot find such InterfaceAlias.

I listed all interfaces on my Windows but there's no sign of any vpn connection. All helps are appreciated, thank you!


Thanks to @DavidBrabant, it seems that it is a bug that Microsoft has not fixed since Windows Vista. I then followed one of the solutions on that kb article: using .Net Class. The result is still the same as before: no sign of any vpn connection. My input and output look like this:

PS C:\WINDOWS\system32> [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces().NetworkInterfaceType
Wireless80211
Wireless80211
Ethernet
Loopback
Tunnel
Tunnel

I haven't tried the second resolution which is "Use the GetAdaptersAddresses API" because I don't know how. Anyone knows? Or did I miss something from the .Net framework?

2
Regarding your last sentance, did you see this? support.microsoft.com/kb/2549091 This is a bug that hasn't gotten fixed through Windows 7 or Windows 8.David Brabant
@David I see, Thanks!Benny

2 Answers

3
votes

Since I can't comment and/or +1 anything because of switching to new account. I want to mention that above Antonio's solution works just fine. You have to use common sense and understand things a little more. I will elaborate on Antonio's message. Understand that the people who are answering you are either coding professionals or IT professionals. So they answer in assumption you are one as well. Please do not -1 anything if you haven't tried it and don't understand it. ASK they will help you and explain more if needed.

Set-DnsClientServerAddress -InterfaceAlias Corporate -ServerAddresses 8.8.8.8 

Let's break this down. So what is this saying?

Set-DnsClientServerAddress

This is assuming you're already connected to the VPN. as Antonio actually mentioned.

you have to connect to the VPN first

Ok now that we have the understanding that this command through powershell assumes we're connected to the VPN (Only 1 by the way not more than 1).

Let's tackle the rest of the command.

-InterfaceAlias Corporate

Ok so those who code undestand that -InterfaceAlias is a Parameter to the Set-DnsClientServerAddress command. Then following that parameter you have attributes. Now that attribute can either be TEXT (aka a String) or a boolean value (aka $True or $False). So in this case he is saying that his vpn is called Corporate. Now with most Windows stuff. Windows will accept strings un quoted if it's all 1 word. However if your VPN Name has a space in it then it will not accept it. you would have to encapsulate your string with quotes. for example.

-InterfaceAlias "My VPN"

So in this case you need to know what your VPN Name is. If you don't know what your VPN Name is, please go to the following location.

Control Panel -> Netwok and Sharing Center -> Change Adapter Settings (left hand side) -> net find your VPN Adapter.

Alright so the last bit.

-ServerAddresses 8.8.8.8

So this ServerAddresses property is already strictly data typed to an IP address or multiple IP addreseses. So in this case you would need to know the DNS Server you wish to request DNS resolution from and replace it (8.8.8.8 = Google outside DNS server). So for example

-ServerAddresses 10.1.10.254

Now this will set the DNS server to be 10.1.10.254 for this VPN Adapter. Kill the VPN and then start it up again. Open a command prompt and type the following

ipconfig/all 

This will show you all your current adapters. For your VPN adapter it should show your updated DNS. If you still can't resolve DNS names it possibly has to do with your Type of DNS server and you will have to probably specify a DNS suffix manually as well. See the following article for more details.

https://superuser.com/questions/966832/windows-10-dns-resolution-via-vpn-connection-not-working

Hope this helped. Sometimes us Senior IT guys just don't have the time to type it all out for business owners and/or new to the trade IT personnel.

-Grafix

1
votes

To be able to change the interface DNS of a windows VPN you have to connect to the VPN first then use the PS command

Set-DnsClientServerAddress -InterfaceAlias Corporate -ServerAddresses 8.8.8.8 

I did it and after that I was able to join the windows 10 to the domain; also first you have to create the VPN using the PS command

Add-VpnConnection -Name "My VPN" -ServerAddress "x.x.x.x" -TunnelType Pptp -EncryptionLevel Required -AuthenticationMethod MSChapv2 -AllUserConnection  -RememberCredential -PassThru