NetworkingDsc icon indicating copy to clipboard operation
NetworkingDsc copied to clipboard

NetAdapterName: InterfaceNumber doesn't seem to be working as it should

Open kungfoome opened this issue 5 years ago • 3 comments

System.InvalidOperationException: A network adapter matching the parameters was not found. Please correct the properties and try again.

Details of the scenario you tried and the problem that is occurring

Doesn't seem to find the adapter based off the filter. Looking at the Find-Adapter function, I show:

VERBOSE: Find-NetworkAdapter: Finding network adapters matching the parameters. VERBOSE: Find-NetworkAdapter: Found all network adapters because no filter parameters provided. VERBOSE: Find-NetworkAdapter: 2 network adapters were found matching the parameters. System.InvalidOperationException: Please adjust the parameters or specify IgnoreMultipleMatchingAdapters to only use the first and try again.

Looking at the code https://github.com/PowerShell/NetworkingDsc/blob/3db6d5ea444ee60ca4ffd8fd4e134763cd070e08/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1#L235

And it appears you need the parameter IgnoreMultipleMatchingAdapters to be true and you need to specify the adapter number.

Find-NetworkAdapter -InterfaceNumber 1 -IgnoreMultipleMatchingAdapters $true -verbose

Suggested solution to the issue

Not sure what this variable would be used for to be honest, so can't provide a solution. I'm assuming it's for other filters that return more than 1 adapter and it shouldn't. In this case, I feel like if specify an interface number, it should just return that number from the array and not get the multiple matching error.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

NetAdapterName RenameNetAdapterPrivate {
            NewName           = 'Private'
            DriverDescription = 'Hyper-V Virtual Ethernet Adapter'
            InterfaceNumber   = 1
        }

The operating system the target node is running

OsName : Microsoft Windows Server 2016 Standard OsOperatingSystemSKU : StandardServerEdition OsArchitecture : 64-bit WindowsBuildLabEx : 14393.2828.amd64fre.rs1_release_inmarket.190216-1457 OsLanguage : en-US OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

Name Value


PSVersion 5.1.14393.2828
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.2828
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

NetAdapterName NetworkingDsc 7.0.0.0

kungfoome avatar Feb 28 '19 10:02 kungfoome

I think one solution might be: Change the Find-NetAdapter so that if the InterfaceNumber is specified and $IgnoreMultipleMatchingAdapters is not implicitly set in the config then it should automatically default to true. This I think would implement the behavior you're expecting. Is that correct?

You are correct: I originally put the InterfaceNumber in so that you could do something like this:

NetAdapterName RenameNetAdapter1AsPrivate {
            NewName           = 'Private'
            DriverDescription = 'Hyper-V Virtual Ethernet Adapter'
            InterfaceNumber   = 1
        }
NetAdapterName RenameNetAdapter2AsInternal {
            NewName           = 'Internal'
            DriverDescription = 'Hyper-V Virtual Ethernet Adapter'
            InterfaceNumber   = 2
        }

But you're right - the above would fail without the IgnoreMultipleMatchingAdapters = $true.

Could you confirm you think the above behavior change would solve the issue?

PlagueHO avatar Mar 01 '19 22:03 PlagueHO

@PlagueHO Thats correct. Based off documentation and just what you would expect without reading documentation, you should only get 1 network adapter back based on what InterfaceNumber is doing. With this assumption, you shouldn't also need the IgnoreMultipleMatchingAdapters. If i do set it as true, such that:

NetAdapterName RenameNetAdapter1AsPrivate {
            NewName           = 'Private'
            DriverDescription = 'Hyper-V Virtual Ethernet Adapter'
            InterfaceNumber   = 1
            IgnoreMultipleMatchingAdapters  = $true
        }
NetAdapterName RenameNetAdapter2AsInternal {
            NewName           = 'Internal'
            DriverDescription = 'Hyper-V Virtual Ethernet Adapter'
            InterfaceNumber   = 2
            IgnoreMultipleMatchingAdapters  = $true
        }

It does work as it should.

So maybe something like

if($PSBoundParameters.ContainsKey('InterfaceNumber'))
{
    if($PSBoundParameters.ContainsKey('IgnoreMultipleMatchingAdapters'))
    {
         $IgnoreMultipleMatchingAdapters = $_.IgnoreMultipleMatchingAdapters
    }
    else
    {
        $IgnoreMultipleMatchingAdapters = $true
    }
}

kungfoome avatar Mar 03 '19 04:03 kungfoome

Cool. Thanks @kungfu71186 - I'll leave it open for community comment, but assume that we'll make the proposed change.

PlagueHO avatar Mar 03 '19 07:03 PlagueHO