Anyone know why this might be failing? It just returns that I have a bad parameter. I'm thinking it is the path but everything lookst okay. I'm running this against a stand alone host.
-
$vcsVMPath = "[DS2_RAID5_C] VCS/VCS.vmx"
$host2 = Read-Host "Enter the FQDN of ESX host number two"
Connect-VIServer -Server $host2 -User root -Password password
Function ImportTemplate
{param ($TarTempPath, $newName)
$vmFldrObj = Get-View -Id (Get-Folder -Name 'vm').ID
$asTemplate = $false
$tarResourcePool = (Get-View (Get-VMHost -Name $host2).ID).parent
$hostMOR = $tarHost.summary.host
$vmFldrObj.RegisterVM_Task($TarTempPath,$newName, $asTemplate, $tarResourcePool, $hostMOR)
}
ImportTemplate -TarTempPath $vcsVMPath -newName "VCS"
Is the variable $tarHost initialised somewhere ?
Otherwise your $hostMOR will contain a $null value and that could explain the "bad parameter" message.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry, accidently trimmed that line out of the code when I submitted it into the forum.
Here is the correct function.
-
$vcsVMPath = "[DS2_RAID5_C] VCS/VCS.vmx"
$host2 = Read-Host "Enter the FQDN of ESX host number two"
Connect-VIServer -Server $host2 -User root -Password password
$tarHost = Get-View (Get-VMHost -Name $host2).ID
Function ImportTemplate
{param ($TarTempPath, $newName)
$vmFldrObj = Get-View -Id (Get-Folder -Name 'vm').ID
$asTemplate = $false
$tarResourcePool = $tarHost.parent
$hostMOR = $tarHost.summary.host
$vmFldrObj.RegisterVM_Task($TarTempPath,$newName, $asTemplate, $tarResourcePool, $hostMOR)
}
ImportTemplate -TarTempPath $vcsVMPath -newName "VCS"
-
Here is the error I'm recieveing. Nothing which is being caught by VMware.
Exception calling "RegisterVM_Task" with "5" argument(s): "A specified paramete
r was not correct.
"
At C:\Documents and Settings\Administrator\Desktop\textvcsAdd.ps1:15 char:27
+ $vmFldrObj.RegisterVM_Task <<<< ($TarTempPath,$newName, $asTemplate, $tarReso
urcePool, $hostMOR)
-
If I were specifying a bad path I should recieve one of these faults correct?
FileFault Thrown if there is an error accessing the files on disk.
InvalidDatastore Thrown if the operation cannot be performed on the target datastores.
Thanks for the help.
Fisk
I was passing a computeResource object rather then a resourcePool object.
Thanks for the help.
Fisk