Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kungfoome opened this issue Feb 28, 2019 · 3 comments
Open
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.

Comments

@kungfoome
Copy link

kungfoome commented Feb 28, 2019

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 kungfoome changed the title NetAdapterName: InterfaceNumber and InterfaceIndex doesn't seem to be working NetAdapterName: InterfaceNumber doesn't seem to be working as it should Feb 28, 2019
@PlagueHO PlagueHO added the needs investigation The issue needs to be investigated by the maintainers or/and the community. label Mar 1, 2019
@PlagueHO
Copy link
Member

PlagueHO commented Mar 1, 2019

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 PlagueHO added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. and removed needs investigation The issue needs to be investigated by the maintainers or/and the community. labels Mar 1, 2019
@kungfoome
Copy link
Author

@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
    }
}

@PlagueHO
Copy link
Member

PlagueHO commented Mar 3, 2019

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

@SteveL-MSFT SteveL-MSFT added this to Help Wanted in powershell/dscresources May 14, 2019
@SteveL-MSFT SteveL-MSFT removed this from Help Wanted in powershell/dscresources Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants