when i use the tenmlate and OSCustomizationSpec create a linux vm ,I can't define the linux system name and i can't fine the parameter define this
An error occurred:
New-VM -Template $Template -DiskStorageFormat Thin -Datastore $Datastore -Name 1000000 -OSCustomizationSpec $osCustomization -ResourcePool $ResourcePool
New-VM : 2019/4/26 9:42:42 New-VM The operation for the entity "centos7.4_4c4g_100g_vmtools_yum_ntp_model" failed with the following message: "A specified parameter was not correct: spec.identity.hostname" 所在位置 行:11 字符: 2 + New-VM -Template $Template -DiskStorageFormat Thin -Datastore $Data ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-VM], InvalidArgument + FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
Try something like this.
It uses a temporary OSCustomizationSPec, that way you don't have to change the original.
Since the Customization Manager can't prompt you, you will have to provide the hostname via the NamingScheme and NamingPrefix parameters.
$cust = New-OSCustomizationSpec -OSCustomizationSpec $osCustomization -Name TempLinux -Type NonPersistent
$cust = Set-OSCustomizationSpec -OSCustomizationSpec $cust -NamingScheme fixed -NamingPrefix MyHost
New-VM -Name TestVMLinux -Template $template -Datastore $datastore -DiskStorageFormat Thin -VMHost $esx -OSCustomizationSpec $cust
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference