VMware Cloud Community
xpermental
VMware Employee
VMware Employee

Get-OSCustomizationSpec

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

0 Kudos
4 Replies
nnedev
VMware Employee
VMware Employee

Hi,

If customization fails you should see some errors. Can you please post them here.

Regards,

Nedko Nedev

PowerCLI Development Team

Regards, Nedko Nedev PowerCLI Development Team
xpermental
VMware Employee
VMware Employee

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: (Smiley Happy , ParameterBindingE

xception

+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor

e.Cmdlets.Commands.NewVM

0 Kudos
admin
Immortal
Immortal

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

xpermental
VMware Employee
VMware Employee

Thanks for the help. I fixed this issue. I had the wrong customization name.

0 Kudos