VMware Cloud Community
jdurlewanger
Contributor
Contributor
Jump to solution

New-VM Value cannot be null.

I am getting the following error when attempting to deploy a VM from a template:

PSMessageDetails :
Exception : VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.VimException: 7/1/2021 3:41:04 PM New-VM Value cannot be null.
Parameter name: collection ---> System.ArgumentNullException: Value cannot be null.
Parameter name: collection
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at VMware.VimAutomation.WorkloadManagement.Impl.V1.WMObnProvider.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList, String contextRelationName)
at VMware.VimAutomation.WorkloadManagement.Impl.V1.WMObnProvider.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList)
at VMware.VimAutomation.Sdk.Impl.V1.CoreServiceImpl.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList, String contextRelationName)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.GetObjectsByNameCore(PropertyInfo parameter, String objectName)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectByNameCore(PropertyInfo parameter, String objectName)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectByName(PropertyInfo parameter)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectsByName()
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.SelectObjectsByName()
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
--- End of inner exception stack trace ---
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
TargetObject :
CategoryInfo : NotSpecified: (:) [New-VM], VimException
FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

I do not see a 'collection' parameter so I am a little confused.
Local powercli version: VMware PowerCLI 12.1.0 build 17009493

Code line:
New-VM -Name $ServerName -Template $Template[0].Name -OSCustomizationSpec $ServerName -Datastore $dataStore.Name -ResourcePool $resourcepool.Name -verbose -RunAsync -confirm:$false

All the variables I am using are not null so which parameter am I missing that would cause 'collection' to be null?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could try an upgrade to PowerCLI 12.3.

If that doesn't help, I suggest opening an SR


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

12 Replies
LucD
Leadership
Leadership
Jump to solution

Are you by any chance using a regional setting that is not en-US?
Do a Get-Culture.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jdurlewanger
Contributor
Contributor
Jump to solution

Using US English

 

1033 en-US English (United States)

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you already try adding the Portgroup parameter?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jdurlewanger
Contributor
Contributor
Jump to solution

Do I need the portgroup parameter if I am using distributed networks and cluster resources?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The Portgroup parameter is optional and accepts VSS and VDS portgroups.
I just mentioned it because there were some reports of a similar error where adding the Portgroup parameter fixed it.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jdurlewanger
Contributor
Contributor
Jump to solution

I just tried adding a portgroup and it still errors out with the ambiguous "Value cannot be null."

PSMessageDetails :
Exception : VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.VimException: 7/6/2021 8:47:05 AM New-VM Value cannot be null.
Parameter name: collection ---> System.ArgumentNullException: Value cannot be null.
Parameter name: collection
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at VMware.VimAutomation.WorkloadManagement.Impl.V1.WMObnProvider.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList, String contextRelationName)
at VMware.VimAutomation.WorkloadManagement.Impl.V1.WMObnProvider.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList)
at VMware.VimAutomation.Sdk.Impl.V1.CoreServiceImpl.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList, String contextRelationName)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.GetObjectsByNameCore(PropertyInfo parameter, String objectName)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectByNameCore(PropertyInfo parameter, String objectName)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectByName(PropertyInfo parameter)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectsByName()
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.SelectObjectsByName()
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
--- End of inner exception stack trace ---
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
TargetObject :
CategoryInfo : NotSpecified: (:) [New-VM], VimException
FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

Here is the command I am using:
New-VM -Name $ServerName -Template $Template[0] -OSCustomizationSpec $ServerName -Datastore $dataStore -ResourcePool $resourcepool -confirm:$false -NetworkName $Networkname -Portgroup $Portgroup.Name -verbose -RunAsync

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Remove the NetworkName parameter, that is obsolete for VDS portgroups


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jdurlewanger
Contributor
Contributor
Jump to solution

I dropped the networkname parameter and I am still getting the ambiguous error:


PSMessageDetails :
Exception : VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.VimException: 7/6/2021 9:06:49 AM New-VM Value cannot be null.
Parameter name: collection ---> System.ArgumentNullException: Value cannot be null.
Parameter name: collection
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at VMware.VimAutomation.WorkloadManagement.Impl.V1.WMObnProvider.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList, String contextRelationName)
at VMware.VimAutomation.WorkloadManagement.Impl.V1.WMObnProvider.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList)
at VMware.VimAutomation.Sdk.Impl.V1.CoreServiceImpl.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList, String contextRelationName)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.GetObjectsByNameCore(PropertyInfo parameter, String objectName)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectByNameCore(PropertyInfo parameter, String objectName)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectByName(PropertyInfo parameter)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectsByName()
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.SelectObjectsByName()
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
--- End of inner exception stack trace ---
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
TargetObject :
CategoryInfo : NotSpecified: (:) [New-VM], VimException
FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could try an upgrade to PowerCLI 12.3.

If that doesn't help, I suggest opening an SR


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

jdurlewanger
Contributor
Contributor
Jump to solution

@LucD thank you for all your help on this! When I updated to the latest version the error changed and is a little more descriptive but is still not getting me in the right direction. Here is the error:
writeErrorStream : True
PSMessageDetails :
Exception : VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.VimException: 7/6/2021 10:00:51 AM New-VM Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at VMware.VimAutomation.ViCore.Impl.V1.Service.VmServiceImpl.GenerateCloneSpec(StorageResourceInterop datastore, VimClient newClient, List`1 hardDisks, VirtualMachine sourceVM, ConfigTarget configTarget, String resourcePoolId, VMHostInterop host, OSCustomizationSpecInterop customization, String datastoreId,
Nullable`1 diskStorageFormat, String description, Boolean allowNested, StoragePolicy storagePolicy, Boolean isVmEncrypted, Boolean isEncryption, Nullable`1 sevEnabled, Boolean skipHardDisks, String[] networks, VirtualPortGroupBaseInterop[] portgroups, CryptoSpec cryptoSpec, CryptoKeyId cryptoKeyId,
VirtualMachineProfileSpec[] profileSpecs, Nullable`1 bootDelayMillisecond)
at VMware.VimAutomation.ViCore.Impl.V1.Service.VmServiceImpl.NewVM(TemplateInterop template, VMHostInterop vmHost, String name, VIContainerInterop resourceContainer, FolderInterop location, StorageResourceInterop datastore, Nullable`1 diskStorageFormat, OSCustomizationSpecInterop customization, Boolean allowNested,
Boolean isRequestedAsync, String description, Nullable`1 haRestartPriority, Nullable`1 haIsolationResponse, Nullable`1 drsAutomationLevel, AdvancedOption[] options, KeyProviderInterop keyProvider, StoragePolicyInterop storagePolicy, ReplicationGroupInterop replicationGroup, Boolean skipHardDisks, String[] networks,
VirtualPortGroupBaseInterop[] portgroups, Nullable`1 sevEnabled, Nullable`1 bootDelayMillisecond)
at VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM.DoWork(VIAutomation client, List`1 moList)
at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.DoWork(VIConnection connection, List`1 moList)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.DoWorkEx(VIConnection connection, List`1 moList)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ConnectionDispatchHelper.ExecuteRunlist(Dictionary`2 runlist, DoWorkDelegate doWorkDelegate, UidDispatchHelper uidDispatchHelper, List`1 result)
--- End of inner exception stack trace ---
TargetObject :
CategoryInfo : NotSpecified: (:) [New-VM], VimException
FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}

Command: New-VM -Name $ServerName -Template $Template[0] -OSCustomizationSpec $ServerName -Datastore $dataStore -ResourcePool $resourcepool -confirm:$false -Portgroup $Portgroup -verbose -RunAsync
I have verified that each variable object only contains 1 item and they are all related to the same datacenter and cluster.
Do you have any suggestions or is there something I am not seeing in this error message?

I had to switch from calling object property name to just the object. 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not really.

I would start with leaving out some parameters, starting with OSCustomizationSpec and later perhaps RunAsync.
But that is just a wild guess.

You could also check the vpxd log, that could provide more feedback on the actual API call the cmdlet is making.
In the VCSA you can configure the Logging temporarily to Verbose to get more info in the vpxd log.

I'm not sure you mentioned this already, but is this is in PS v7.* on a Linux box?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jdurlewanger
Contributor
Contributor
Jump to solution

This is PSversion 5.1 on Windows.
I was able to get a vm deployed from the template after removing the -runasync and portgroup parameters. So I think the issue was related to the powercli version but could have been a combination of version and parameters since I tested deploying without the above parameters before updating. I think I will try on a server that has not updated the vmware powercli module to confirm.

Thank you @LucD for all your help!

0 Kudos