This issue only occurs in system center Orchestrator 2012 sp1 run .net script activity.
Just upgraded to PowerCLi 6.3.0.8258, OS running powershell 3.0.
had to invoke-command all the runbook activities to run powercli code in 64bit.
All is well until I try the the new-VM command in a .net script activity. The get-template command returns only 1 object, the correct template object, but new-vm command sees it as multiple values and not know what to do then dumps. This entire script works just fine outside of orchestrator on the same server with identical creds. Verified only one session in $defaultviserver. Have tried run behavior in flatten/non-flatten mode, same thing. I am hoping there is something simple I am overlooking, please advise if you have ran across this, thanx.
Here is the error in Log:
TemplatePath = Win10-Template
folderPath = Windows10
New-VM Template parameter: Could not find any of the objects specified by name.
New-VM The specified parameter 'Template' expects a single value, but your name criteria 'Win10-Template' corresponds to multiple values.
----------------------------------------------------------------------------------------------------------------------------
sample script below
-----------------------------------------------------------------------------------------------------------------------------
#invoke command for 64bit support for new powercli snapins
$result = Invoke-Command -ScriptBlock {
add-pssnapin vmware.vimautomation.core
$rmt_user = "runbook"
$rmt_password = "runbookpassword"
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($rmt_user, (ConvertTo-SecureString -String $rmt_password -AsPlainText -Force))
#Connects to vCenter/ESX(i)
$conn = connect-viserver "VcenterServer" -Credential $cred
$VMName = "EASTVM"
$Hostname = "host1"
$Datastore = "store1"
$trace += "datacenter = $datacenter `r`n"
$trace += "hostname = $hostname `r`n"
$trace += "datastore = $datastore `r`n"
$trace += "vmname = $vmname `r`n"
$templatePath = (get-template -location EAST -name Win10-Template)
$FolderPath = get-folder -Location EAST -Name "Windows10"
#$templatePath = $templatePath -replace '\s',''
#$FolderPath = $FolderPath -replace '\s',''
$trace += "TemplatePath = $templatepath `r`n"
$trace += "folderPath = $folderpath`r`n"
$trace
New-VM -Name $VMName -VMHost $Hostname -Datastore $Datastore -Template $templatePath
# -location $FolderPath
$Error
} -ComputerName localhost #end invoke command for 64bit support
as the script is wrapped around invoke-command for 64bit mode I can only capture what $error produces.
This is the error
New-VM | Template parameter: Could not find any of the objects specified by name. |
New-VM | The specified parameter 'Template' expects a single value, but your name criteria 'Win10-Template' corresponds to multiple values. |
The other way I can potentially workaround this would be using the integration pack:
This one supports system center 2012 sp1 Orchestrator but does not list vsphere 6.0 support
Deploying the VMware vSphere Integration Pack for System Center 2012 - Orchestrator
Could it be that you have multiple connections open at the time you do the New-VM?
Display the content of $global:defaultviservers, just before the New-VM cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$global:defaultviservers, just before the New-VM cmdlet, shows 1 connection only. :smileyconfused:
I'm not sure what you are trying to do with these two lines?
$templatePath = (get-template -location EAST -name Win10-Template)
$templatePath = $templatePath -replace '\s',''
The Get-Template cmdlet returns a Template object, not a string.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
quite right the two objects are not strings and dont need to have spaces eliminated, good catch. I have remmed out the two lines in the original post.
I have narrowed this down further.
its only the -template param or the $templatepath object that is holding up this whole thing.
I can do
New-VM -Name $VMName -VMHost $Hostname -Datastore $Datastore -location $folderpath
and it will go thru just fine.
Would you mind showing the exact error message you're getting on the New-VM cmdlet with the Template parameter?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
as the script is wrapped around invoke-command for 64bit mode I can only capture what $error produces.
This is the error
New-VM | Template parameter: Could not find any of the objects specified by name. |
New-VM | The specified parameter 'Template' expects a single value, but your name criteria 'Win10-Template' corresponds to multiple values. |
The other way I can potentially workaround this would be using the integration pack:
This one supports system center 2012 sp1 Orchestrator but does not list vsphere 6.0 support
Deploying the VMware vSphere Integration Pack for System Center 2012 - Orchestrator
Did you already display the contant of $templatePath just before the New-VM cmdlet?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference