rchaganti / DSCResources

Custom DSC resource modules by PowerShell Magazine
http://www.powershellmagazine.com
61 stars 26 forks source link

error in DSC resource cNetworkAdapter.psm1 version 2.6.1 #6

Closed GeriOnline closed 7 years ago

GeriOnline commented 8 years ago

Hello,

I played a little bit with your DSC resource cNetWorkAdapter v. 2.6.1 and detected a script error in that module. In the function Test-TargetResource in line 221 you check with Get-VMNetworkAdapter if the specified netadapter exists and assign the result to variable $NetAdapterExists. However in the following script code you only reference a variable $AdapterExists, which is nowhere defined. So Test-TargetResource in some cases returns a wrong result.

I have changed the function code to always using the variable $NetAdapterExists and now it seems that Test-TargetResource returns always correct results (see the changed in my attached file).

It would be nice if you could take account of these changes in future versions.

Best regards Gerhard Glenk

cVMNetworkAdapter.psm1.zip

rchaganti commented 8 years ago

Thank you! There are a few updates planned for this resource. I will make these changes as well during that. Also, these resources (cVMNetworkAdapter, cVMNetworkAdapterVlan, and cVMNetworkAdapterSettings) will be moved to xHyper-V module in PowerShell team's official repository later this week. They will be a part of the official DSC resource kit soon.

GeriOnline commented 8 years ago

Great to hear that you will move your resources to the xHyper-V module. For that I have 2 wishes / suggestions:

  1. cNatSwitch: As switchtype NAT no longer exists inTP5 of Server 2016 and Win10 Build 14322 it would be nice if you change this resource to the new "NAT way" (see https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows/user_guide/setup_nat_network?branch=scooley-client-nat).
  2. cVMNetworkAdapterSettings: Can you please add the network adapter property "Device Naming" to this resource? Tnak you in advance.
rchaganti commented 8 years ago

Thanks for the suggestions. I have not tested the NatSwitch on TP5 yet. I will update it accordingly. For item 2, can you expand a bit and explain what is that you are looking for? What is Device Naming property? What does it relate to in the network adapter properties?

GeriOnline commented 8 years ago

Device Naming: It's a new property for virtual network adapters of Hyper-V VMs since TP4 and Win10 Build 10586, also in TP5 and Win10 14322. Open Settings of a VM in Hyper-V, select and expand a Network Adapter of that VM and click Advanced Features. Scroll down the right Windows. At the end you will find the oprion "Device Naming" (see attached screen shot). devicenaming If checked it means later on in the guest VM you can identify that network adapter via it's Hyper-V name (and not only "Ethernet" ) through the advanced property "Microsoft Hyper-V Network Adapter" (see screen shot) nicprops With Powershell you can find this with the following command: Get-NetAdapterAdvancedProperty | where Displayname –eq “Hyper-V Network Adapter Name” | select Name, DisplayValue So you can easily rename the ethernet adapters in the guest VM with the name defined in the Hyper-V settings. Hope this helps.

GeriOnline commented 8 years ago

Some more info for cNatSwitch: Here ist a small function to create a NAT switch the "new way":

Function New-NatSwitch ( $Name, $InternalIPInterfaceAddressPrefix, $PrefixLength, $GatewayIP ) { New-VMSwitch -Name $Name -SwitchType Internal

find InterfaceIndex of the network adapter for the newly created internal switch

$ifindex = (Get-NetAdapter | where {$_.Name -match $Name}).ifIndex
New-NetIPAddress -IPAddress $GatewayIP -PrefixLength $PrefixLength -InterfaceIndex $ifindex
New-NetNat -Name $Name -InternalIPInterfaceAddressPrefix "$InternalIPInterfaceAddressPrefix/$PrefixLength"

}

Funnily enough this also works in TP4 and Win10 Build 586. And in addition it seems that there are no problems when removing all these objects in contrast to the implementation of the NATswitch.

GeriOnline commented 8 years ago

A little help for Device Naming: For my lab I have already modified the cNetworkAdapterSettings. Find this Version in the attached ZIP. Note: I also had to extend the schema.mof file because of the new parameter "Device Naming". cVMNetworkAdapterSettings.zip

rchaganti commented 8 years ago

Thanks for the information and changes. I will make these changes and submit a PR upstream to xHyper-V. Of course, with due credits!

GeriOnline commented 8 years ago

Hello Ravikanth, what's about new versions of the DSC resources we discussed above? You said these changes will be merged with the xHyper-V resource. But up to now I cannot find any newer versions. Thank you Gerhard

rchaganti commented 8 years ago

@GeriOnline I am pushing an updated module (cVMnetworkAdapter) to align it with the feedback from xHyper-V PR. I will eventually move this update to xHyper-V. Submitting modules to MSFT repo is hard and I am trying to catch up on the tech debt I created.

GeriOnline commented 7 years ago

Great to see that you published a new version 3.0.0.0 of your cHyper-V DSC resource in the Powershell Gallery with fixes for my reported bug and implementation of my suggestion for 'Device Naming'. So I no longer need to manage my private fork. Thank you very much.

I think I can close now this issue. Good luck with submitting the modules to the MSFT repo. Gerhard