BUG in Set-VMNICVLAN?

Nov 2, 2010 at 2:50 PM

Hi,

When I try to change VLAN ID for a network card using the following command I will get the following error:

Command:

get-vmnic server01 | set-vmnicvlan -vlanid 0

Error:

Property 'DesiredEndpointMode' cannot be found on this object; make sure it exists and is settable.
At C:\Program Files\Modules\hyperv\Network.ps1:524 char:61
+                if ($Vlan.DesiredEndpointMode -ne 5 ) {$Vlan. <<<< DesiredEndpointMode=5   ; $Vlan.put() | out-null }
    + CategoryInfo          : InvalidOperation: (DesiredEndpointMode:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

You cannot call a method on a null-valued expression.
At C:\Program Files\Modules\hyperv\Network.ps1:524 char:96
+                if ($Vlan.DesiredEndpointMode -ne 5 ) {$Vlan.DesiredEndpointMode=5   ; $Vlan.put <<<< () | out-null }
    + CategoryInfo          : InvalidOperation: (put:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Get-WmiObject : Invalid object path
At C:\Program Files\Modules\hyperv\Network.ps1:525 char:42
+                $VlanSetting=Get-WmiObject <<<<  -ComputerName $Nic.__Server -Namespace $HyperVNamespace -q "associato
rs of {$Vlan} where assocClass=MSVM_NetWorkElementSettingData"
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Property 'TrunkedVLANList' cannot be found on this object; make sure it exists and is settable.
At C:\Program Files\Modules\hyperv\Network.ps1:526 char:85
+                if ($VlanSetting.TrunkedVLANList -notContains $VlanID) {$VlanSetting. <<<< TrunkedVLANList += $VlanID
; $VlanSetting.put() | out-null}
    + CategoryInfo          : InvalidOperation: (TrunkedVLANList:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

You cannot call a method on a null-valued expression.
At C:\Program Files\Modules\hyperv\Network.ps1:526 char:130
+                if ($VlanSetting.TrunkedVLANList -notContains $VlanID) {$VlanSetting.TrunkedVLANList += $VlanID ; $Vla
nSetting.put <<<< () | out-null}
    + CategoryInfo          : InvalidOperation: (put:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Any suggestions to what is going wrong?

But despite the error the vlanid is changed.

Apr 26, 2012 at 7:28 PM

I just ran into this and there is a missing variable.  Open network.ps1 and go to line 524 and you will find "

 foreach-object {Get-WmiObject -Namespace -ComputerName $Nic.__Server $HyperVNamespace -q ...

Note how the namespace is at the wrong place, so move it:

 foreach-object {Get-WmiObject -Namespace $HyperVNamespace -ComputerName $Nic.__Server -q ...

Apr 26, 2012 at 9:02 PM

I use the following command and it's working for me

Get-VM "P2V" |Get-VMNIC |Set-VMNICVLAN -VLANID "11"

May 16, 2012 at 2:16 PM

This Does't work for me...

I do the followign commands that I've got from get-vmbuildscript, then I've just added vmnicVlan

$NIC = Add-VMNIC              -VM   $VM 

Set-VMNICAddress              -NIC  $NIC -MAC 00155D129D25
set-VMNIcVLAN                  -NIC $NIC  -VLANID "28"

It doesn't generate any error, but it does nothing, VLAN is always 0 but,  MaAcddress is correctly assigned.

Any idea?

Thanks in advance

May 25, 2012 at 12:22 PM

I'll answer to myself, perhaps other people had the same problem

set-VMNicVLAN command requires an associated switch was previously created on the VM