Solved

Powershell and VMNicSpecDTO


Badge +2
Looks like there may have been a change in doing:
New-NTNXObject -Name VMNicSpecDTOin Powershell which is causing my script to fail adding a NIC to a VM.
When creating the object there is now an object (or array?) of 2 types, the first is AdapterType_Enum which is unexpected and breaks the script, the second one is VMNicSpecDTO which is what is actually required. Forcing it to instead use $nicspec[1] and the script works as expected.

I'm using:


PowerCLI D:> Get-NTNXCmdletsInfoversion 5.1 BuildVersion 2.0-release5.1-dev-28022017 RestAPIVersion v1

example:

PowerCLI D:> $nicSpec = New-NTNXObject -Name VMNicSpecDTOPowerCLI D:> $nicSpec.networkuuid = "d0ebba66-bb01-4b72-85f6-708156358ee3"The property 'networkuuid' cannot be found on this object. Verify that the property exists and can be set.At line:1 char:1+ $nicSpec.networkuuid = "d0ebba66-bb01-4b72-85f6-708156358ee3"+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException PowerCLI D:> $nicSpecE1000macAddress : networkUuid : model : requestedIpAddress : requestIp : adapterType : portId : PowerCLI D:> $nicSpec[0].gettype()IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True AdapterType_Enum System.EnumPowerCLI D:> $nicSpec[1].gettype()IsPublic IsSerial Name BaseType -------- -------- ---- -------- True False VMNicSpecDTO System.Object PowerCLI D:> $nicSpec[1].networkuuid = "d0ebba66-bb01-4b72-85f6-708156358ee3"PowerCLI D:> Add-NTNXVMNIC -Vmid $AHVVM -SpecList $nicSpec -Servers $DestAHVClusterNameAdd-NTNXVMNIC : Cannot bind parameter 'SpecList'. Cannot convert value "E1000" to type "Nutanix.Prism.DTO.Acropolis.VMNicSpecDTO". Error: "Invalid cast from 'Nutanix.Prism.DTO.Acropolis.AdapterType_Enum' to 'Nutanix.Prism.DTO.Acropolis.VMNicSpecDTO'."At line:1 char:38+ Add-NTNXVMNIC -Vmid $AHVVM -SpecList $nicSpec -Servers $DestAHVClusterName+ ~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Add-NTNXVMNIC], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Nutanix.Prism.PS.Cmds.Acropolis.AddVMNIC PowerCLI D:> Add-NTNXVMNIC -Vmid $AHVVM -SpecList $nicSpec[1] -Servers $DestAHVClusterNametaskUuid -------- 00d49b8e-cf15-4afc-9c00-ac073f800499

icon

Best answer by sandeepmp 10 August 2017, 08:07

MattDonovan

This issue is fixed in AOS - 5.1.1 / CMDlets - 2.1.1 version.

Key Value--- -----version 5.1.1BuildVersion 2.1.1-release5.1.1-dev-05302017RestAPIVersion v1

PS C:Windows> $new = New-NTNXObject -Name VMNicSpecDTO
PS C:Windows> $new
macAddress :networkUuid :model :ipAddress :requestedIpAddress :requestIp :adapterType :portId :

PS C:Windows> $new[0]
macAddress :networkUuid :model :ipAddress :requestedIpAddress :requestIp :adapterType :portId :

View original

6 replies

Userlevel 2
Badge +10
This is a bug on our side. Somehow while creating the object for VmNicDTO it is capturing the enum in the dto.
The workaround for this would be to use
$nic[1].networkUuid = $network.uuid

However the workaround does seem to allow defining $nic variable, but then it breaks at Add-NTNXVMNICAdd-NTNXVMNIC -Vmid $vmId -speclist $nicAdd-NTNXVMNIC : Cannot bind parameter 'SpecList'. Cannot convert value "E1000" to type "Nutanix.Prism.DTO.Acropolis.VMNicSpecDTO". Error: "Invalid cast from 'Nutanix.Prism.DTO.Acropolis.AdapterType_Enum' to 'Nutanix.Prism.DTO.Acropolis.VMNicSpecDTO'."At line:1 char:37+ Add-NTNXVMNIC -Vmid $vmId -speclist $nic+ ~~~~~+ CategoryInfo : InvalidArgument: (:) [Add-NTNXVMNIC], ParameterBindingException+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Nutanix.Prism.PS.Cmds.Acropolis.AddVMNIC

So you need
Add-NTNXVMNIC -Vmid $vmId -speclist $nic[1]
Userlevel 4
Badge +19
MattDonovan

This issue is fixed in AOS - 5.1.1 / CMDlets - 2.1.1 version.

Key Value--- -----version 5.1.1BuildVersion 2.1.1-release5.1.1-dev-05302017RestAPIVersion v1

PS C:Windows> $new = New-NTNXObject -Name VMNicSpecDTO
PS C:Windows> $new
macAddress :networkUuid :model :ipAddress :requestedIpAddress :requestIp :adapterType :portId :

PS C:Windows> $new[0]
macAddress :networkUuid :model :ipAddress :requestedIpAddress :requestIp :adapterType :portId :
Badge +2
great, thanks, will upgrade soon.

also the guestOperatingSystem property is blank for all my VMs, even if NGT is running, is that expected?

PowerCLI D:> Get-NTNXVM -SearchString m30vmId : 00052165-4685-4721-6567-a0369f750aa8::14de3922-3f74-4543-8ad7-c76aaacd05cauuid : 14de3922-3f74-4543-8ad7-c76aaacd05capowerState : onvmName : M30guestOperatingSystem : ipAddresses : {192.168.21.130}hypervisorType : kKvm
Userlevel 4
Badge +19
MattDonovan

Currently "Guest OS is applicable only for ESX Vms".
Badge +7
We worked around this issue by inspecting the New-NTNXObject object and looking for the correct index location.

`$nicSpec = New-NTNXObject -Name VMNicSpecDTO`

On 5.0 `$nicSpec` has two items `[AdapterType_Enum, VMNicSpecDTO]`
On 5.1 `$nicSpec` has one item `[VMNicSpecDTO]`

By looking for the index location of the element of name 'VMNicSpecDTO' powershell supports all version (5.0, 5.1, 5.1.1)



$nicSpec = New-NTNXObject -Name VMNicSpecDTO # Nutanix Powershell Cmdlet 5.0, $nicSpec is array of length 2 [AdapterType_Enum, VMNicSpecDTO] # Nutanix Powershell Cmdlet 5.1 $nicSpec is array of length 1 [VMNicSpecDTO] $nicSpecDTOCounter = 0 $nicSpec | % {$nicSpecCounter = 0}{ if ($_.gettype().Name -eq 'VMNicSpecDTO') { $nicSpecIndex = $nicSpecCounter $nicSpecDTOCounter = $nicSpecDTOCounter + 1 } $nicSpecCounter++ }
You can then refer to the $nicSpec variable like so

Instead of hard coding `$nicSpec[1]`, you can reference the variable `$nicSpec[$nicSpecIndex]`
Badge
Hi
I am running 2017.02.23 version
Is this issue fixed on CE version too?
Wondering if it is fixed on ce-2017.07.20.

Reply