Resetting an IPV6 interface with powershell - windows

Since netsh is going to become obsolete in the near future,I was looking for a replacement which does the equivalent to resetting the netsh ipv6 interface (netsh interface ipv6 reset).
I was looking for alternatives to run the above command either with powershell or any other script. On running netsh interface ipv6 reset,I can see alot of operations being performed,example:
Resetting Compartment Forwarding, OK!
Resetting Compartment, OK!
Resetting Control Protocol, OK!
I'm not sure how exactly to go about doing all of these with powershell or any other script.Is there any way to perform the above with powershell?
From going through the references online I understand that it overwrites the following registry,
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\ to the default values.Where exactly is the default configuration for ipv6 stored?

Related

Anyone used Unified Write Filter (uwfmgr) and netsh together? I'm seeing some off things after running netsh and then rebooting

I've have a Win10IoT Enterprise image I've built.
It is running with Unified Write Filter enabled on the system (C:) volume.
I have the following registry exclusions added to the system disk (the only protected volume) to allow changing IP addresses via netsh to persist and be saved through the filter.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class{4d36e972-e325-11ce-bfc1-08002be10318}
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces
When I boot the machine with the uwf filter ON I do the following actions....
Run netsh to set a static IP, Subnet, and gateway
Verify the commanbd worked with ipconfig
Check the NIC card GUI in Windows and also verify it looks good there.
Everything at this point looks great. I now reboot the machine (uwf filter still on).
When the machine reboots I check the IP address again via ipconfig and the NIC GUI to verify they are still good.
This is when things get odd. The ipconfig looks fine, but in the GUI window the IP is listed as the last static IP address I set with the uwf filter OFF (192.168.0.20 in this example). If I click the advanced settings there are two address listed under the IP Addresses, my expected 192.168.0.50 address as well as the old 192.168.0.20.
Some more info, the machine will respond to pings to 192.168.0.50 but will not respond to 192.168.0.20. I'm guessing there is another registry setting somewhere that is getting reverted causing the GUI to not update correctly. Anyone have any ideas?
Thanks!
Post reboot images....
I had the same problem.
But when I add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nsi to my exclusion list, it works

NewNetIPAddress: ActiveStore vs. PersistantStore

I'm trying to set a new IP-Address by using a powershell script. I use this command:
New-NetIPAddress -InterfaceAlias $interfaceName -IPAddress $_.IPAddress -AddressFamily IPv4 -PrefixLength $maskLegth
However, on a disconnected interface i get this error:
New-NetIPAddress : Inconsistent parameters PolicyStore PersistentStore and Dhcp Enabled
But when i set the -PolicyStore to ActiveStore, the script will run without errors:
New-NetIPAddress -InterfaceAlias $interfaceName -IPAddress $_.IPAddress -AddressFamily IPv4 -PrefixLength $maskLegth -PolicyStore ActiveStore
I'm not quite sure what this property does, since after restart the settings still are in place. Are there any drawbacks here? Or why does this error even come up?
New-NetIPAddress : Inconsistent parameters PolicyStore PersistentStore and Dhcp Enabled
PersistentStore is separate from ActiveStore, and there is also separate GPO store.
These stores are firewall and network configurations.
ActiveStore contains configuration for this computer.
GPO store is configuration from local group policy.
Active store is curentlly active configuration, and includes both GPO and Persistent store.
Problem you are getting is because Persistent store is set to DHCP and you are configuring static address, which makes not sense.
first disable DHCP in active store and then set IP for interface.
For information about these stores and how to set them see:
https://learn.microsoft.com/en-us/powershell/module/netsecurity/set-netfirewallsetting?view=win10-ps

How to specify DNS server for a VPN Connection by PowerShell?

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?
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
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

How to change the binding order of network adapters using commandline(wmi, netsh, vbscript, etc...)

I have several network connections that are connected to different networks.
and I want to make sure that a certain network connection is at the top of the list.
so I want to programmatically script changes to the binding order of network adapters for a windows(win 2008 server and win 2003 server)
Is it any way to change the binding order programmatically?just use wmi, netsh, vbscript, edit regstry or other script or command line tools.
I found edit registry registry HKLM\system\currentcontrolset\services\TCPIP\linkage\ -> bind value,
is a way on windows 2008 server.
use "netstat -rn" can found binding order is changed. but the on the networking advenced UI(ncpa.cpl)
the order is not changed.
and looks it not working on windows 2003 server.
Is any one have idea How to change the binding order of network adapters using commandline?
Thanks
This looks to be what you are after:
http://realworldwindows.blogspot.com/2006/11/changing-network-provider-order-in.html
Alternatively, you could easily script a batch file that disables the primary adapter so that the adapter you want to be primary takes over. Then re-enable the original one again.
Example:
#echo off
netsh interface set interface "Local Area Connection" DISABLED
:: do something here on the secondary connection
netsh interface set interface "Local Area Connection" ENABLED

IISExpress returns a 503 error from remote machines

I'm attempting to test a website I have running in a local IISExpress instance with some other machines / devices on my local network. I am running Win7 Pro.
When I first attempt to browse to my machine from another machine on my local network segment, I get a 400 error: Hostname is invalid.
I understand that I need to grant remote access to the ACL with a command on the elevated command prompt like:
netsh http add urlacl url=http://mymachinename:50333/ user=everyone
Now I get a 503 service is unavailable error.
Windows Firewall is currently shut off, and I am able to browse my local IISExpress instance with the address http://localhost:50333
What is the final piece to this configuration puzzle?
It looks like you are missing a binding information entry in applicationhost.config file.
Open your applicationhost.config file. Possible locations are:
%userprofile%\Documents\IISExpress\config\applicationhost.config
$(solutionDir)\.vs\config\applicationhost.config (VS2015)
Failing that, inspect the output from iisexpress.exe to be sure.
Locate your WebSite entry and add following binding with your machine name.
<binding protocol="http" bindingInformation=":50333:your-machine-name" />
Restart IIS Express
There was only 1 thing that worked for me.
using *:portnumber:* was no good. Yes, after doing that and making sure the Windows Firewall was open, I could connect to the port, but I still got the "503" error.
I tested a few things locally, and discovered that only http://localhost worked. Using the real IP address (not 127.0.0.1, but, for instance, 192.168.1.50), still returned a 503 even on the local machine. I tried using the real host name in the bindings, but IIS Express refused to start. This may actually have something to do with how the host name was being resolved. I didn't explore that further.
Finally, I ended up using this configuration:
<binding protocol="http" bindingInformation="*:53351:localhost" />
<binding protocol="http" bindingInformation="192.168.1.50:53351:*" />
In that way, I was able to connect from a remote machine using http://192.168.1.50:53351.
After wasting more than 3h on such a full subject I decided to share my setup with you.
My configuration is Visual Express 2012 for Web update 4 on windows 8. This was my first come back to MS VS since studies (at least 8 years) and now I'm sure that linux rules. On django this kind of setup took me 10min of searching documentation.
turn off firewall for testing
netsh advfirewall set allprofiles state off
setup bindings in my case local address is localIP=192.168.1.102 (because links can not contain nonnumeric domain, use it below instead of mylocaldomain.com, see stackoverflow policy)
in Documents\IISExpress\config\applicationhost.config
<bindings>
<binding protocol="http" bindingInformation="*:53351:mylocaldomain.com" />
<binding protocol="http" bindingInformation="*:53351:localhost" />
</bindings>
add autorun for ISS Express start service automatically
<site name="NeuronCharts" id="2" serverAutoStart="true">
Add some weird rules to http server (I still do not know if this is nesseary)
netsh http add urlacl url=http://mylocaldomain.com:53351/ user=everyone
run IISExpress manually not from VS IDE
you will see that ISSExpress is registering bindings
run browser http://mylocaldomain.com:53351
if it is working then we can add firewall rule
add firewall rule
netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=53351 remoteip=any action=allow
set remoteip to any if you want to access you server from outside world if you want to access for local network use localsubnet
start firewall
netsh advfirewall set allprofiles state on
check again if everything is working on local and public ip
Wish you luck
Rafal
Found the problem had to do with a bad urlacl mapping. To figure this out:
netsh http show urlacl
and look for things like http://+:80/ or the port you are binding to.
Then use
netsh http delete url=<the url from the list>
This fixed the problem for me.
Nothing worked for me. Finally I found iisexpress-proxy
See my answer https://stackoverflow.com/a/33623399/631527
Another solution is ngrok
What helped me, was right clicking the 'IISExpress' icon, 'Show All applications'. Then selecting the website and I saw which aplicationhost.config it uses, and the the correction went perfectly.
The problem is updating the applicationhost.config file inside the web folder instead of the solution's. The solution config file is the one to change
Regarding Anthony Rizzolo's answer: in Windows 8.1, I had to type like this:
netsh http delete urlacl url=<the url from the list>
For example:
netsh http delete urlacl url=http://+:8689/
After solution of #vikomall don't forget to start VS as adminisrator.
This fix it for me.
None of the answers above worked for me.
I have had two entries in netsh for the same service
netsh http show urlacl
One using a strong wildcard, the other one using a weak wildcard.
Removing the one with the weak wildcard did the job.
More about the strong and weak wildcard in the context of netsh
When the host element of a UrlPrefix consists of a single plus sign
(+), the UrlPrefix matches all possible host names in the context of
its scheme, port and relativeURI elements, and falls into the strong
wildcard category.
When an asterisk (*) appears as the host element, then the UrlPrefix
falls into the weak wildcard category. This kind of UrlPrefix matches
any host name associated with the specified scheme, port and
relativeURI that has not already been matched by a strong-wildcard,
explicit, or IP-bound weak-wildcard UrlPrefix. This host specification
can be used as a default catch-all in some circumstances, or can be
used to specify a large section of URL namespace without having to use
many UrlPrefixes.
https://learn.microsoft.com/en-gb/windows/desktop/Http/urlprefix-strings

Resources