1

So I was on here with a different question, and I've made some progress in Identifying the issue. I have a network that isn't allowed to have DHCP, and all of our MTR Pcs live on it static. intermittently they come up like this after their nightly reboot,

InterfaceAlias       : Ethernet 3
InterfaceIndex       : 21
InterfaceDescription : PANGP Virtual Ethernet Adapter
NetProfile.Name      : Unidentified network
IPv4Address          : 169.254.24.253
                       10.245.2.160
IPv4DefaultGateway   :
DNSServer            : 134.20.248.5
                       134.20.248.21

enter image description here enter image description here

you'll notice that there is a link local address taking precedent over the set static, and Wireshark is actually seeing a DHCP request going out. Bumping the port, disabling and reenabling the Nic, or even unplugging the Ethernet cable and putting it back all fix this, and they return to their static address. while we are tracking down the issue, I'm trying to deploy a Power shell script to simply Bump the PCs NIC this is what I have, but it's not quite working (super newb to Powershell) at this point; just trying to get the Wifi adaptor to disable.

Example of my test environment here:

InterfaceAlias       : Ethernet 3
InterfaceIndex       : 21
InterfaceDescription : PANGP Virtual Ethernet Adapter
NetProfile.Name      : Unidentified network
IPv4Address          : 10.245.2.160
IPv4DefaultGateway   :
DNSServer            : 134.20.248.5
                       134.20.248.21

InterfaceAlias       : Wi-Fi
InterfaceIndex       : 19
InterfaceDescription : Intel(R) Wi-Fi 6 AX201 160MHz
NetProfile.Name      : Space Interweb
IPv4Address          : 192.168.1.154
IPv4DefaultGateway   : 192.168.1.1
DNSServer            : 192.168.1.1

InterfaceAlias       : Ethernet 2
InterfaceIndex       : 13
InterfaceDescription : Check Point Virtual Network Adapter For Endpoint VPN Client
NetAdapter.Status    : Disconnected

enter image description here

Code I'm attempting

PS C:\Users\flatbe> if (Get-NetIPConfiguration | ? IPv4Address -match "10"){ Get-NetIPConfiguration | ? interfaceAlias -match "Wi" | Disable-NetAdapter -Confirm:$false }

I have since tried

>> Get-NetIPConfiguration |
>>     ? InterfaceIndex -match "19" |
>>     Restart-NetAdapter

which works but this doesnt

>> Get-NetIPConfiguration |
>>     ? IPv4Address[] -match "141" |
>>     Restart-NetAdapter

how would I write this properly?

I stepped up to an If statement and this confuses me most. This seems like it should work since the statement is outputting true and the code in the braces works stand alone.

PS C:\Users\flatbe> #Requires -RunAsAdministrator
>> $IPAddress = (Get-NetIPAddress -AddressFamily IPV4 -InterfaceIndex 21).IPAddress
>> write-output $IPAddress
>> Write-output if($IpAddress -match "169"){
>>  Get-NetIPConfiguration | ? InterfaceAlias -match "wi" | Restart-Netadapter}
169.254.182.44
if
True

 Get-NetIPConfiguration | ? InterfaceAlias -match "wi" | Restart-Netadapter
Barrington
  • 15
  • 4
  • 1
    Match is a regex operator. By the brackets on IPv4Address i assume its an array, to see if an array contains an item, you must use -contains ie ? IPv4Address[] -contains "141" That is if i'm interpreting your question correctly. – Silbee Aug 24 '22 at 13:43
  • Thanks for the input! it returns this error if I try that: ```? : The specified wildcard character pattern is not valid: IPv4Address[] At line:1 char:26 + Get-NetIPConfiguration | ? IPv4Address[] -contains "192" | Restart-Ne ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Where-Object], WildcardPatternException + FullyQualifiedErrorId : RuntimeException,Microsoft.PowerShell.Commands.WhereObjectCommand``` – Barrington Aug 24 '22 at 14:14
  • Ive also tried this ```Get-NetIPConfiguration | ? Ipv4Address -match "192" | Restart-NetAdapter``` No error but also no result – Barrington Aug 24 '22 at 14:24
  • It is unclear to me how you set up your network adapter’s IPv4 configuration in the first place. Is it truly set to static? From the GUI? Or is this perhaps a transient network adapter that keeps getting recreated? Please describe the _actual_ and _desired_ setup in greater detail instead of just throwing around some Powershell snippets and some screenshots. – Daniel B Aug 24 '22 at 18:18
  • This is the onboard NIC yes it was and always say it is set to static in the GUI. The set up is as desired 90% of the time until randomly one day it comes up with that link local address stacked on top. again this is across 80+ systems. Ill Post a picture of the GUI as well in the original post. Politeness is appreciated – Barrington Aug 25 '22 at 19:28

1 Answers1

0

So this script works to temporarily fix my problem. If anyone knows why the link local assignment might be getting generated please let me know here. This script is helping dramatically.

    $IPAddress = (Get-NetIPAddress -AddressFamily IPV4 -InterfaceAlias Ethernet).IPAddress

 write-output $IPAddress

 if($IpAddress -match "169"){

    try { Get-NetIPConfiguration | Where-Object InterfaceAlias -match "Ethernet" | Restart-Netadapter

       

    }

    catch {

        Write-Output "An Error Occurred"

    }

 }

I trigger this on log in to the Skype profile on the MTR NUC, I only allow it to run once. that way if we are able to enable dhcp later on this wont sit there bumping a NIC with a 169 octet over and over again forever.

Barrington
  • 15
  • 4