Link to home
Create AccountLog in
Avatar of owenlloyd
owenlloydFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VMware Powercli - Cant clone vm to template - error message

The following script and error is returned:

PowerCLI C:\scripts> get-vm $vm | New-Template -name vmTemp -Location (Get-Datacenter Datacenter)
Get-Datacenter : 15/11/2012 15:04:17    Get-Datacenter        Datacenter with name 'Datacenter' was not found using the specified filter(s).
At line:1 char:65
+ get-vm $vm | New-Template -name vmTemp -Location (Get-Datacenter <<<<  Datacenter)
    + CategoryInfo          : ObjectNotFound: (:) [Get-Datacenter], VimException
    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatacenter

New-Template : Cannot bind parameter 'Location'. Cannot convert the "" value of type "System.Management.Automation.PSCustomObject" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.VIContainer".
At line:1 char:49
+ get-vm $vm | New-Template -name vmTemp -Location <<<<  (Get-Datacenter Datacenter)
    + CategoryInfo          : InvalidArgument: (:) [New-Template], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewTemplate

Open in new window

Avatar of Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)
Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)
Flag of United Kingdom of Great Britain and Northern Ireland image

this is one line that will do it....

Get-Template WindowsXPTemplate | New-VM –Name <target-vm-name> -VMHost <name of vmhost> -Datastore <name of datastore>

Open in new window

Avatar of owenlloyd

ASKER

Thanks but that line clone 'from' a template.  I need to clone a vm 'To' a template.  I also need to specify which datacenter as I have more than one.  All of VMware's examples use the '-location' parameter followed by the name of the datacenter, this is a compulsory parameter.

More info: vm is currently powered off and adequate storage exists on host.
ASKER CERTIFIED SOLUTION
Avatar of Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)
Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks this worked, but strangely today I try the original code again and this worked fine and did not return the original error?  Strange, same virtual center, host and vm to clone as well.  Weird.