Q: In Windows 10 Pro, beside malware, what would cause an interface index value to change on its own?
Scenario:
Powershell execution policy = allsigned
Only a specific user group has execute permissions on the script and the script is signed.
A Powershell script is run on a laptop by the end user which changes the network settings of the device based on one of two locations. No, DHCP is not an option and why is irrelevant; also, the Powershell script has been running without issues for almost
7 months now. The script has a variable which contains the interface index value (2) of the Ethernet adapter as it was listed at the time the script was composed. The end user then goes to run the script as normal except this time the script fails with the
following error message:
"Remove-NetIPAddress : No matching MSFT_NetIPAddress object found by CIM query for instances of the ROOT/StandardCimv2/MSFT_NetIPAddress class on the CIM server: SELECT * FROM MSFT_NetIPAddress WHERE ((InterfaceIndex = 2)) AND ((AddressFamily = 2)). Verify
query parameters and retry..."
When the interface index for the Ethernet adapter is checked you notice that its value, which used to be a 2, is now a 3. What caused this to change?
P.S.
The variable was being declared as:
$intIndex = 2
but is now being declared as:
$intIndex = (Get-NetIPAddress|where{$_.InterfaceAlias -eq 'Ethernet' -and $_.AddressFamily -eq 'IPv4'}).InterfaceIndex
and the revised declaration has resolved the error message being generated.