I am trying to add man VM's using a CSV file but I can nver get the os customization to run. The vm's are created and placed in the right datastore. Below is the script I am running and my CSV file.
Connect-VIServer x.x.x.x
$vms = Import-CSV C:\NewVMs.csv
foreach ($vm in $vms){
$Template = Get-Template $vm.template
$VMHost = Get-VMHost $vm.host
$Datastore = Get-Datastore $vm.datastore
$OSCustomization = Get-OSCustomizationSpec $vm.customization
New-VM -Name $vm.name -OSCustomizationSpec $OSCustomization `
-Template $Template -VMHost $VMHost -Datastore $Datastore -RunAsync
CSV file.
Name,Template,Host,Datastore,Customization
test,W2K8R2E64,vipriesxpr01.firstcdn.com,datastore14,W2K8R2E64
Hi,
If customization fails you should see some errors. Can you please post them here.
Regards,
Nedko Nedev
PowerCLI Development Team
I do get this error. I am running against a ESXi 4.1 hosts and vCenter.
New-VM : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.ViC
ore.Types.V1.OSCustomization.OSCustomizationSpec' required by parameter 'OSCust
omizationSpec'. Specified method is not supported.
At C:\massaddvm.ps1:16 char:49
+ New-VM -Name $vm.name -OSCustomizationSpec <<<< $OSCustomization `
+ CategoryInfo : InvalidArgument: ( , ParameterBindingE
xception
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor
e.Cmdlets.Commands.NewVM
It seems that Get-OSCustomizationSpec returned more than one value. Are you connected to multiple servers? Or does the name of the customization spec (the one you read from the CSV) contain wildcards?
-
PowerCLI development team
Thanks for the help. I fixed this issue. I had the wrong customization name.