It doesn't look like there is a way to import a vm from a datastore by pointing at its .vmx file? Can I do it with new-vm? I didn't see an option for this within the R-CLI either....
Anyone?
It doesn't look like there is a way to import a vm from a datastore by pointing at its .vmx file? Can I do it with new-vm? I didn't see an option for this within the R-CLI either....
Anyone?Folders have a RegisterVM_Task method that should work.
Try something like this:
$folder = get-folder vm $folderView = get-view $folder.ID $pool = get-resourcepool resources $poolView = get-id $pool.ID $folderView.RegisterVM_Task("/path/to/vm", "VM Name", $false, $poolView.MoRef, $null)
You'll have to play around with the first argument. In case you didn't guess I didn't actually test this
The DiskPath parameter of New-VM lets you specify a disk or disks.
Thanks to CShanklin and adias for giving me a couple options. The most Powershell friendly and easy to use one is listed below. I was having issues getting it to work becuase I was putting the actual path to the VM (/vmfs/volume....) Once I combined their 2 examples and realized I could use the VC pathing name it all JUST WORKED.
New-VM -DiskPath "[Datastore Name] dir/vmname.vmx" -Name "newVM Name" -VMHost $hostname
Can you give another example of syntax for the DatastoreName?
The example from Adias seems to have been removed.
Eric