Highlighted
Contributor
Contributor

'expects a single value/corresponds to multiple values' error scripting New-vm in PowerCLI

Jump to solution

I have been tasked with creating some 800+ Virtual Desktops so naturally this is something I would want to script.  After reading through the vast knowledge bases here I was able to create what I thought was good code.  It worked when I was just "write-host"ing the command lines to see if the variable creation/uasge was working ok.  When I removed the write-host lines and tried to use actual new-vm commands, I started getting various "The specified parameter 'VMHost' expects a single value, but your name criteria 'xxx-vm53.yyyyyyyyy.com' corresponds to multiple values." errors.  Here is my code, specifics marked out:

Add-PSSnapin VMWare.VimAutomation.Core # Add PowerCli functionality to script environmen t
$creds = get-vicredentialstoreitem -file "c:\temp\credfile.xml" # Access hashed password file to authentice with "sys" service account
connect-viserver -server $creds.host -user $creds.user -password $creds.password
$host1 = get-cluster "HVD1" | get-vmhost | sort-object 'memoryusagemb'|select-object -first 1 |foreach {$_.name} # Get VMWare Host with least memory usage from 'HVD1' cluster host listing
$dstore = get-datastore "vdi_*" | sort-object "FreeSpaceMB" -descending | select-object -first 1 |foreach {$_.name} # Get datastore disk with most freespace from VDI_* listing
$VMBaseName = "XX-P01-HVD" # Setting for Commercial Hosted XenDesktop names
$Template = get-template Template-CBD-XD-XP | select-object -first 1|foreach{$_.name} # Setting for Commercial Hosted XenDesktop Template
$OSCustSpec = "CBD-XD XP Hosted" # Setting for Commercial Hosted XenDesktop Customization script
$loc = "Desktops" # Setting for XenDesktop folder
$ResPool = get-resourcepool XX-P01-HVD| select-object -first 1|foreach{$_.name}  # Setting for Commercial Hosted XenDesktop Resource Pool
[int]$FirstNumber=0
[int]$HostTotal=0
[int]$ctr=0

$FirstNumber = Read-Host "Enter the first number for VMWare Host Range"
$HostTotal = Read-Host "Enter the quantity for VMWare Host Range"
$HostNumber = $FirstNumber
$HostFinal = $HostNumber+$HostTotal

do {
$vmname = $vmbasename + $HostNumber
new-vm -vmhost $host1 -name $VMName -ResourcePool $ResPool -Location $loc -datastore $dstore -DiskStorageFormat Thin -Template $template -OSCustomizationspec $OSCustSpec # Execute creation of new VMWare host
start-vm $VMName # start VM to begin Customization process
$HostNumber++
$ctr += 1
if ($ctr -eq 5){write-host;write-host "Pausing 10 Minutes";sleep -s 600; $ctr=0;write-host} # sleep for 600 seconds every 5 VMs to avoid overloading vSphere hosts
} until ($HostNumber -eq $HostFinal)

Here are my errors:


New-VM : 3/23/2011 5:42:22 PM    New-VM        The specified parameter 'VMHost'
expects a single value, but your name criteria 'xxx-vm53.yyyyyyyyy.com' corres
ponds to multiple values.
At C:\temp\xx_deploy.ps1:31 char:7
+ new-vm <<<<  -vmhost $host1 -name $VMName -ResourcePool $ResPool -Location $l
oc -datastore $dstore -DiskStorageFormat Thin -Template $template -OSCustomizat
ionspec $OSCustSpec # Execute creation of new VMWare host
    + CategoryInfo          : InvalidResult: (System.Collecti...dObjectInterop
   ]:List`1) [New-VM], VimException
    + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResu
   ltsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

New-VM : 3/23/2011 5:42:23 PM    New-VM        The specified parameter 'Resourc
ePool' expects a single value, but your name criteria 'XX-P01-HVD' corresponds
to multiple values.
At C:\temp\xx_deploy.ps1:31 char:7
+ new-vm <<<<  -vmhost $host1 -name $VMName -ResourcePool $ResPool -Location $l
oc -datastore $dstore -DiskStorageFormat Thin -Template $template -OSCustomizat
ionspec $OSCustSpec # Execute creation of new VMWare host
    + CategoryInfo          : InvalidResult: (System.Collecti...dObjectInterop
   ]:List`1) [New-VM], VimException
    + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResu
   ltsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

New-VM : 3/23/2011 5:42:23 PM    New-VM        ResourcePool parameter: Could no
t find any of the objects specified by name.
At C:\temp\xx_deploy.ps1:31 char:7
+ new-vm <<<<  -vmhost $host1 -name $VMName -ResourcePool $ResPool -Location $l
oc -datastore $dstore -DiskStorageFormat Thin -Template $template -OSCustomizat
ionspec $OSCustSpec # Execute creation of new VMWare host
    + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...ol ResourcePo
   ol:RuntimePropertyInfo) [New-VM], ObnRecordProcessingFailedException
    + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotF
   oundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

I did have multiple values for some of the entries, which is why I was trying to parse it out with the '-first 1' and outside of the script, the values come back seemingly fine.

Any Help?

0 Kudos
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

And that is the cause of the problem.

You feed the New-VM indeed only 1 name, and the cmdlet will, through OBN, try to resolve that name into an object.

But since there are 2 connections, it will get an object returned by each connection.

Hence the multiple value message.

Check if you have multiple Connect-VIServers in the script and perhaps close all connections before the script starts.

Or switch to single mode with the Set-PowerCLIConfiguration cmdlet.


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

View solution in original post

0 Kudos
11 Replies
Highlighted
User Moderator
User Moderator

There is no need to use the %{$_.Name} after the Select -First 1.

The New-VM probably sees an array of chars.


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

0 Kudos
Highlighted
Contributor
Contributor

Nope, that worked even less.  Now I get the errors:

New-VM : 3/24/2011 7:43:30 AM    New-VM        One or more objects are specifie
d by name. There is no server list explicitly specified, so an attempt was made
to determine a single server by the  managed objects passed to the cmdlet as a
rguments. However the arguments come from more than one server which makes it i
mpossible to unambiguously  select single server.
At C:\temp\hn_deploy.ps1:31 char:7
+ new-vm <<<<  -vmhost $host1 -name $VMName -ResourcePool $ResPool -Location $l
oc -datastore $dstore -DiskStorageFormat Thin -Template $template -OSCustomizat
ionspec $OSCustSpec # Execute creation of new VMWare host
    + CategoryInfo          : InvalidResult: (System.Collecti...1.VIConnection
   ]:List`1) [New-VM], ViServerConnectionException
    + FullyQualifiedErrorId : Core_ObnSelector_GetClientListFromCmdletParamete
   rs_AmbiguousServer,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

New-VM : 3/24/2011 7:43:30 AM    New-VM        One or more objects are specifie
d by name. There is no server list explicitly specified, so an attempt was made
to determine a single server by the  managed objects passed to the cmdlet as a
rguments. However the arguments come from more than one server which makes it i
mpossible to unambiguously  select single server.
At C:\temp\hn_deploy.ps1:31 char:7
+ new-vm <<<<  -vmhost $host1 -name $VMName -ResourcePool $ResPool -Location $l
oc -datastore $dstore -DiskStorageFormat Thin -Template $template -OSCustomizat
ionspec $OSCustSpec # Execute creation of new VMWare host
    + CategoryInfo          : InvalidResult: (System.Collecti...1.VIConnection
   ]:List`1) [New-VM], ViServerConnectionException
    + FullyQualifiedErrorId : Core_ObnSelector_GetClientListFromCmdletParamete
   rs_AmbiguousServer,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

New-VM : 3/24/2011 7:43:31 AM    New-VM        OSCustomizationSpec parameter: C
ould not find any of the objects specified by name.
At C:\temp\hn_deploy.ps1:31 char:7
+ new-vm <<<<  -vmhost $host1 -name $VMName -ResourcePool $ResPool -Location $l
oc -datastore $dstore -DiskStorageFormat Thin -Template $template -OSCustomizat
ionspec $OSCustSpec # Execute creation of new VMWare host
    + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...stomizationSp
   ec:RuntimePropertyInfo) [New-VM], ObnRecordProcessingFailedException
    + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotF
   oundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

And if I run those lines outside of the script, it shows me the whole "DISK09 and Freespace and Capacity" in 3 headered columns.

0 Kudos
Highlighted
User Moderator
User Moderator

That looks as if you have multiple connections open

Can you do

$defaultVIServers

and check if you see more than 1 entry ?


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

0 Kudos
Highlighted
Contributor
Contributor

Interestingly I get 2 lines:

xxx-vmvc02.xxxxxx.yyyyyyyyy.com 443 xxxxxx\user

xxx-vmvc02                      443 xxxxxx\user

0 Kudos
Highlighted
User Moderator
User Moderator

And that is the cause of the problem.

You feed the New-VM indeed only 1 name, and the cmdlet will, through OBN, try to resolve that name into an object.

But since there are 2 connections, it will get an object returned by each connection.

Hence the multiple value message.

Check if you have multiple Connect-VIServers in the script and perhaps close all connections before the script starts.

Or switch to single mode with the Set-PowerCLIConfiguration cmdlet.


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

View solution in original post

0 Kudos
Highlighted
Contributor
Contributor

Sweet, looks like that did it and it kicked off a new clone.  However, it bombed out with "New-VM        The operation for the entity VirtualMachine-vm-251 failed with the following message: "The operation is not supported on the object."

0 Kudos
Highlighted
User Moderator
User Moderator

Do you have snapshots on the source VM ?


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

0 Kudos
Highlighted
Contributor
Contributor

There is a snapshot but when I check the VM.Name object, it's pointing to a different server than the one I'm cloning.  Cloning from a template, btw.

0 Kudos
Highlighted
User Moderator
User Moderator

This "Operation not supported" message can have many causes.

Perhaps you can look in the vCenter log (vpdxnnnn.log) and see if there are any messages that provide more info.


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

0 Kudos
Highlighted
Contributor
Contributor

Hopefully this helps ... log section attached

Message was edited by: LucD Log file contained an activation key, file removed.

0 Kudos
Highlighted
Contributor
Contributor

Thanks for all your assistance. You helped me create a great script! I can send it along and you can share my final with the community if you think it's worthwhile.

Erric Z

0 Kudos