Scripts

Welcome to the Nutanix NEXT community. To get started please read our short welcome post. Thanks!

cancel
Showing results for 
Search instead for 
Did you mean: 

Powershell and VMNicSpecDTO

SOLVED Go to solution
Highlighted
Wayfarer

Powershell and VMNicSpecDTO

Looks like there may have been a change in doing:

New-NTNXObject -Name VMNicSpecDTO

in 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-NTNXCmdletsInfo
version 5.1 
BuildVersion 2.0-release5.1-dev-28022017 
RestAPIVersion v1

 

 

example:

 

PowerCLI D:\> $nicSpec = New-NTNXObject -Name VMNicSpecDTO
PowerCLI 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: (Smiley Happy [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException PowerCLI D:\> $nicSpec E1000 macAddress : networkUuid : model : requestedIpAddress : requestIp : adapterType : portId :

PowerCLI D:\> $nicSpec[0].gettype()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True AdapterType_Enum System.Enum

PowerCLI 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 $DestAHVClusterName
Add-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: (Smiley Happy [Add-NTNXVMNIC], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Nutanix.Prism.PS.Cmds.Acropolis.AddVMNIC

PowerCLI D:\> Add-NTNXVMNIC -Vmid $AHVVM -SpecList $nicSpec[1] -Servers $DestAHVClusterName

taskUuid
--------
00d49b8e-cf15-4afc-9c00-ac073f800499

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Nutanix Employee

Re: Powershell and VMNicSpecDTO

@MattDonovan

 

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

 

Key Value
--- -----
version 5.1.1
BuildVersion 2.1.1-release5.1.1-dev-05302017
RestAPIVersion 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 :

Tags (1)
4 REPLIES
Nutanix Employee

Re: Powershell and VMNicSpecDTO

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-NTNXVMNIC
Add-NTNXVMNIC -Vmid $vmId -speclist $nic
Add-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: (Smiley Happy [Add-NTNXVMNIC], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Nutanix.Prism.PS.Cmds.Acropolis.AddVMNIC

 

So you need

Add-NTNXVMNIC -Vmid $vmId -speclist $nic[1]

Nutanix Employee

Re: Powershell and VMNicSpecDTO

@MattDonovan

 

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

 

Key Value
--- -----
version 5.1.1
BuildVersion 2.1.1-release5.1.1-dev-05302017
RestAPIVersion 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 :

Tags (1)
Wayfarer

Re: Powershell and VMNicSpecDTO

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 m30

vmId : 00052165-4685-4721-6567-a0369f750aa8::14de3922-3f74-4543-8ad7-c76aaacd05ca uuid : 14de3922-3f74-4543-8ad7-c76aaacd05ca powerState : on vmName : M30 guestOperatingSystem : ipAddresses : {192.168.21.130} hypervisorType : kKvm
<snip>
Nutanix Employee

Re: Powershell and VMNicSpecDTO

@MattDonovan

 

Currently "Guest OS is applicable only for ESX Vms".