Powershell - Strange issue with script when searching for Ethernet Adapter - powershell

I'm not even sure if this is a programming issue or something strange in Windows
I am creating a script in PowerShell 4.0 to automate the setting up of a Windows 6in4 tunnel.
The script is working successfully on my machine however when someone else using the same version tries it, the script fails for them.
The sticking point appears to be here
# First Locate Which device is the Ethernet Adapter
$wiredAdapter = Get-NetAdapter | Where-Object {$_.PhysicalMediaType -eq '802.3'}
This line is supposed to get the adapter properties of the Ethernet adapter (On both mine and the other individuals system there is only one)
On my system if I run the line and then output the results I get the following
PS C:\Users\Timothy> $wiredAdapter
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
Ethernet Qualcomm Atheros AR8131 PCI-E Gigabi... 3 Up xx-xx-xx-3B-22-78 100 Mbps
However when he tries copying the line directly he gets no output.
Can anyone suggest what's going wrong here?
Thanks in advance.

On my system Get-NetAdapter returns as I'd expect
The same as $ Wired above
PS C:\Users\Timothy> Get-NetAdapter
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
WiFi 3 Atheros AR5007UG Wireless Network Ad... 13 Disconnected 00-1D-0F-B1-82-B9 0 bps
Ethernet Qualcomm Atheros AR8131 PCI-E Gigabi... 3 Up F4-6D-04-3B-22-78 100 Mbps
If I then do (Get-NetAdapter).PhysicalMediaType I get the following
PS C:\Users\Timothy> (Get-NetAdapter).PhysicalMediaType
Native 802.11
802.3
I chose PhysicalMediaType as I was getting strange results off the media type for the Wireless Adapters.
PS C:\Users\Timothy> (Get-NetAdapter).MediaType
802.3
802.3
Still can't figure out why I get this result.
Thanks guys - the problem is that the other system returns different values for the Ethernet card. What's annoying is that the card is the same model as mine
Native 802.11
Unspecified
Unspecified
Unspecified
Unspecified
Unspecified
Unspecified
I did come across the following page using the Get-WMIObject.
http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Script-to-889c9505
However using that my wireless adapters were enumerated as wired adapters :(

Related

Powershell: Determine the current Physical network adapter in use allowing internet connections

I am trying to determine the physical network adapter in use through powershell.
I have some of the pieces for a function I am creating but have issues to determine the actual physical adapter in use:
With Get-NetAdapter -Physical | Select-Object Name, InterfaceDescription, ifIndex, Status I can get the physical network adapters, and if they are up:
Here I get also the interface index (relevant later):
Name
InterfaceDescription
IfIndex
Status
Ethernet
Intel(R) Ethernet Connection (4) I219-V
23
Up
Wi-Fi
Intel(R) Dual Band Wireless-AC 8265
8
Up
With Get-NetRoute -InterfaceIndex <interface index> | Where-Object {$_.AddressFamily -eq 'IPV4'} I can get the routes for all interfaces (2 in this case)
The problem is that both interfaces have a 0.0.0.0/0 route for their respective gateway, so any of them can route me to the "regular" internet (let's say, google.com).
So how do I determine the actual interface in use?. I think that the interface metric in both cases can help me:
ifIndex
DestinationPrefix
NextHop
RouteMetric
ifMetric
8
0.0.0.0/0
192.168.3.1
256
40
23
0.0.0.0/0
192.168.1.1
256
25
So the Ethernet interface (IfIndex = 23) has an IfMetric of 25. As RouteMetric is the same for both, Ethernet Interface will take precedence, in theory.
This shall apply to connections with or without VPN clients (indeed for these tests I am connected through a VPN client) but:
a. I am not 100% sure that this may work every time.
b. What if the Route Metric is different for the interfaces?. What takes precedence: the ifMetric, the RouteMetric or a combination of both?.
Will be glad to read your comments or experiences about this.
Thanks!
It is a combination of the metrics from my experience, however the way I usually get a definitive answer is to run the Test-NetConnection command to a URL or IP and the output of that command will list the interface it used. I use it to ensure traffic goes over our VPN adapter but in your case if you did a Test-NetConnection -ComputerName www.google.com it will return the interface alias of the interface used which you can use to find the ifindex and map it back to the adapter if you have multiple adapters

NetAdapter command gives 'The data is invalid' message

I am trying to rename the Ethernet adapter after creating a VLAN in my script. It currently just creates a new Ethernet x as an adapter.
From what I can find online Get-NetAdapter should display all network adapters and Rename-NetAdapter should work, however I keep getting the following error:
Kind regards,
Tom

Set Static IP Address on all Physical (Wired) Adapters

Using PowerShell, we can easily set a static IP address on an adapter where the InterfaceIndex is known like this:
New-NetIPAddress -InterfaceIndex 17 -IPAddress 192.168.0.1 -PrefixLength 24 -DefaultGateway 192.168.0.254
We would like to be able to set the static IP address on any physical wired adapter. We can get the physical adapters like this:
Get-NetAdapter –Physical
That will return something like this:
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
Ethernet Intel(R) Ethernet Connection (5) 17 Disconnected 00-11-22-33-44-55 1 Gbps
Wi-Fi Intel(R) Wireless LAN 7 Disconnected 00-11-22-33-44-56 72 Mbps
Is there any way to get only the wired adapters and not the wireless
adapters, other than by name (which could be anything)?
Since there may be multiple wired adapters (however rare), and
since we don't know which physical adapter might be used, we would
like to set the static IP address to each wired adapter. What can
we do (something like a "for/each" loop) to set the IP address on
each wired adapter on the PC?
EDIT: In reading some more, it seems that since Windows 8 that the wired adapter may be configured to be statically-named "Ethernet". Since we're only targeting Windows 10, can we really just add a query to get only adapters whose name is like 'Ethernet%?
I would use
Get-NetAdapter -Physical | Where-Object { $_.PhysicalMediaType -eq "802.3" }
This seems to be a good indicator of physical ethernet only adapters, and it will get adapters that don't have "Ethernet" in the Description/DisplayName. WLAN devices will have Native 802.11 (or otherwise indicative of a Wireless Adapter).
Do Get-NetAdapter | Export-CSV C:\Path\To\CSV to get all properties for all adapters on the system. You may find more properties to leverage in your filtering.
As for setting the IP Address on all ethernet adapters, this should work fine (although I caution that setting the same IP Address on multiple adapters may cause trouble in the however unlikely event that multiple ethernet adapters are in use simultaneously):
$ethernetAdapters = #(Get-NetAdapter -Physical | Where-Object {$_.PhysicalMediaType -eq "802.3"})
$staticIPAddress = "0.0.0.0"
$gateway = "0.0.0.0"
$prefixLength = "24"
foreach ($adapter in $ethernetAdapters) {
New-NetIPAddress -IPAddress $staticIPAddress -AddressFamily IPV4 -DefaultGateway $gateway -PrefixLength $prefixLength -InterfaceIndex $adapter.InterfaceIndex
}
Remember to replace the variables with information for your environment, and specifically the IP address you'll use for the adapters.
You may wish to figure a way to generate a new IP Address for each $adapter, maybe in succession (*.200, *.201 etc.), with a portion that calls out to a centralized file with ip addresses, mac addresses and serial numbers for record keeping.
Have you tried something like
Get-NetAdapter -Physical | Where-Object { $_.Name -match "^Ethernet" }

RavenDB : "Make sure the port is open."

I want to set up a 4.0.4 RavenDB through its setup wizard but it keeps saying that my port 443 isn't open.
Error Message
In my Settings I've double-checked the IP adresses.
192.168.1.28 is my computer.
Everything's fine. 38889 was just a test.
In my Firewall port settings, everything looks ok : NAT/PAT
Same thing with the Windows Firewall
Btw, before you link it to me, I've already read
https://ravendb.net/docs/article-page/4.0/csharp/server/security/common-errors-and-faq
If anyone could help, i'd provide lifetime gratitude :)
Thank you in advance for every answer.
This usually means that something is holding on to that port.
This is frequently Skype or IIS.
Here is how you can figure it (PowerShell):
PS C:\> Get-Process -id (Get-NetTCPConnection -LocalPort 443).OwningProcess
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
1855 78 136472 76416 2,115.61 12812 1 Skype
On My Machine, you can see that Skype is indeed holding this port open. You can change that using:

How to find which IP address is active for communication?

I am using Windows XP Sp3. We are having both wired network and wireless network.
Both will have different IP address range .
Is there any way to find which IP address/Gateway is used to communicate?
i.e. We are having permission to wired network IP range to rdp to our lab machines. But with wireless connection we can't.
Often people forget that and asking me.
If the wireless network is active channel , then it should either try to connect through wired network or it should intimate them. How to achieve this using powershell?
You can get the same information route print shows like this:
Get-WmiObject -Class Win32_IP4RouteTable | select Destination, Mask, NextHop, Metric1
If your network address is 10.0.0.0 you can get the NextHop IP like this:
Get-WmiObject -Class Win32_IP4RouteTable | ? {$_.Destination -eq "10.0.0.0"} | select NextHop
As I understand you should manually add routes to lab machines for wired interface. And you could detemine current route settings with command:
route print
running from windows console (cmd )
Guess this links could be also helpfull to you:
Configure default gateway
Usage route command
Adding static IP route