I am trying to clone a VM using this script (http://communities.vmware.com/message/1291604#1291604) and getting the following error...
The term 'Find-EntityView' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:34 char:22
+ $HS = Find-EntityView <<<< -ViewType HostSystem
+ CategoryInfo : ObjectNotFound: (Find-EntityView:String) [], Com
mandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
ake sure that the assembly containing this type is loaded.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:40 char:78
<<<< ::sparse
+ CategoryInfo : InvalidOperation: (http://VMware.V...eTransforma
tion:String) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Get-VM : 8/27/2010 12:35:53 PM Get-VM VM with name 'TSRM_nc033211' no
t found, using the specified filter(s).
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:57 char:16
+ $vmmor = Get-VM <<<< -name $vmtemplate #Get-Template -Name $vmtemplate
+ CategoryInfo : ObjectNotFound: ( , VimException
+ FullyQualifiedErrorId : Core_ContainerCmdletBase_ObjectNotFoundByName,VM
ware.VimAutomation.Commands.GetVM
Get-View : Cannot validate argument on parameter 'Id'. The argument is null or
empty. Supply an argument that is not null or empty and then try the command ag
ain.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:58 char:22
+ $vmmorview = get-view <<<< $vmmor.id #Get-View (Get-VM -name "WinXPSP2_Basel
ine").id
+ CategoryInfo : InvalidData: ( , ParameterBindingVal
idationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
ation.Commands.DotNetInterop.GetVIView
You cannot call a method on a null-valued expression.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:61 char:32
+ $task = $vmmorview.CloneVM_Task <<<< ($targetview.MoRef,$vmname, $vmcSpec )
+ CategoryInfo : InvalidOperation: (CloneVM_Task:String) [], Runt
imeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Finished
Hi again,
The first error means that there were no enough free memory during the last execution of the script. Try to close the PowerCLI console, to start a new one and run the script again.
But before that you should apply minor fix on this row:
$vmmor = Get-VM -name $vmtemplate Get-Template -Name $vmtemplate
Should be either:
$vmmor = Get-VM -name $vmtemplate
or either:
$vmmor = Get-Template -name $vmtemplate
Current state of the row has no correct powershell syntax.
Vitali
Seems like I don't have this --> http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.VirtualMachine.html#c...
but I don't see how to get this installed. Thanks for the help.
Hi there,
You should replace Find-EntityView with Get-View in the script.
Also check that you are working with the latest PowerCLI version 4.1. ( Get-PowerCLIVersion )
Vitali
PowerCLI team
Replaced Get-EntityView with Get-View and get this....
The term 'Find-View' is not recognized as the name of a cmdlet, function, scrip
t file, or operable program. Check the spelling of the name, or if a path was i
ncluded, verify that the path is correct and try again.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:35 char:16
+ $HS = Find-View <<<< -ViewType HostSystem
+ CategoryInfo : ObjectNotFound: (Find-View:String) [], CommandNo
tFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Get-VM : 8/30/2010 7:52:25 AM Get-VM VM with name 'TSRM_nc033211' was
not found, using the specified filter(s).
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:58 char:16
+ $vmmor = Get-VM <<<< -name $vmtemplate #Get-Template -Name $vmtemplate
+ CategoryInfo : ObjectNotFound: ( , VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
utomation.ViCore.Cmdlets.Commands.GetVM
Get-View : Cannot validate argument on parameter 'VIObject'. The argument is nu
ll or empty. Supply an argument that is not null or empty and then try the comm
and again.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:59 char:22
+ $vmmorview = get-view <<<< $vmmor.id #Get-View (Get-VM -name "WinXPSP2_Basel
ine").id
+ CategoryInfo : InvalidData: ( , ParameterBindingVal
idationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
ation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView
You cannot call a method on a null-valued expression.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:62 char:32
+ $task = $vmmorview.CloneVM_Task <<<< ($targetview.MoRef,$vmname, $vmcSpec )
+ CategoryInfo : InvalidOperation: (CloneVM_Task:String) [], Runt
imeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Finished
Hi again,
I guess that there's a line in your script file that looks like this:
$HS = Find-View -ViewType HostSystem
It should look like this:
$HS = Get-View -ViewType HostSystem
Get-View is the name of the commandlet that currently PowerCLI supports, Find-EntityView was the name in version 1.0 and it is deprecated.
About the second error (Get-VM: 8/30/2010 .......).
There's another row in the script that might need edit in order to work for you:
$vmmor = Get-VM -name $vmtemplate #Get-Template -Name $vmtemplate
The line written in this way will search for virtual machine and this machine will be used for source in the clone operation. If you want to use a template for source you should use the portion that is after the # sign:
$vmmor = Get-Template -Name $vmtemplate
Vitali
PowerCLI team
I made those changes, here is my script...
#Virtual Machine to be created variables
$vmpool = "001.1.0.03HC.010"
$vmname="nc049248"
$vmtemplate= "TSRM_nc033211"
$vmfolder = "001.03.010.6-TLSM"
###############################################################################################
connect-viserver -server $VIServer -user $user -password $password -Protocol $vmprotocol
#sets up vim object
#$HS = Find-EntityView -ViewType HostSystem
$HS = Get-View -ViewType HostSystem
#foreach ($vm in $vmnamearray) {
$vmrSpec = New-Object VMware.Vim.VirtualMachineRelocateSpec
#$vmrSpec.transform = http://VMware.Vim.VirtualMachineRelocateTransformation::sparse
$vmrSpec.transform = http://VMware.Vim.VirtualMachineRelocateTransformation::sparse
#setup resource pool
$pool = get-resourcepool $vmpool
$poolview = get-view $pool.id
$vmrSpec.pool = $poolview.moref
$vmcSpec = New-Object VMware.Vim.VirtualMachineCloneSpec
$vmcSpec.location = $vmrspec
$vmcSpec.powerOn = $false
$vmcSpec.template = $false
#get storage folder
$target = Get-Folder $vmfolder
$targetview = get-view $target.ID
#get template
#$vmmor = Get-VM -name $vmtemplate #Get-Template -Name $vmtemplate
$vmmor = Get-VM -name $vmtemplate Get-Template -Name $vmtemplate
$vmmorview = get-view $vmmor.id #Get-View (Get-VM -name "WinXPSP2_Baseline").id
#clone
$task = $vmmorview.CloneVM_Task($targetview.MoRef,$vmname, $vmcSpec )
#wait-task $task.value
Write-Output "Finished"
Output...
Get-View : 8/30/2010 8:44:37 AM Get-View Exception of type 'System.Ou
tOfMemoryException' was thrown.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:35 char:15
+ $HS = Get-View <<<< -ViewType HostSystem
+ CategoryInfo : NotSpecified: ( , VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
n.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView
Get-VM : Cannot bind parameter because parameter 'Name' is specified more than
once. To provide multiple values to parameters that can accept multiple values,
use the array syntax. For example, "-parameter value1,value2,value3".
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:59 char:53
+ $vmmor = Get-VM -name $vmtemplate Get-Template -Name <<<< $vmtemplate
+ CategoryInfo : InvalidArgument: ( , ParameterBindingE
xception
+ FullyQualifiedErrorId : ParameterAlreadyBound,VMware.VimAutomation.ViCor
e.Cmdlets.Commands.GetVM
Get-View : Cannot validate argument on parameter 'VIObject'. The argument is nu
ll or empty. Supply an argument that is not null or empty and then try the comm
and again.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:60 char:22
+ $vmmorview = get-view <<<< $vmmor.id #Get-View (Get-VM -name "WinXPSP2_Basel
ine").id
+ CategoryInfo : InvalidData: ( , ParameterBindingVal
idationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
ation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView
You cannot call a method on a null-valued expression.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Admin_Scripts\Create
_VMs2.ps1:63 char:32
+ $task = $vmmorview.CloneVM_Task <<<< ($targetview.MoRef,$vmname, $vmcSpec )
+ CategoryInfo : InvalidOperation: (CloneVM_Task:String) [], Runt
imeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Finished
Hi again,
The first error means that there were no enough free memory during the last execution of the script. Try to close the PowerCLI console, to start a new one and run the script again.
But before that you should apply minor fix on this row:
$vmmor = Get-VM -name $vmtemplate Get-Template -Name $vmtemplate
Should be either:
$vmmor = Get-VM -name $vmtemplate
or either:
$vmmor = Get-Template -name $vmtemplate
Current state of the row has no correct powershell syntax.
Vitali
It is working now. Thank you so much for your assistance with this issue, I really appreciate it!!!!