Automation

 View Only
  • 1.  Importing existing VM?

    Posted Apr 02, 2008 06:39 PM

    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?



  • 2.  RE: Importing existing VM?

    Posted Apr 02, 2008 07:28 PM

    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 :smileyhappy:



  • 3.  RE: Importing existing VM?

    Posted Apr 02, 2008 07:36 PM

    The DiskPath parameter of New-VM lets you specify a disk or disks.



  • 4.  RE: Importing existing VM?

    Posted Apr 03, 2008 03:37 PM

    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



  • 5.  RE: Importing existing VM?

    Posted Aug 25, 2009 02:34 PM

    Can you give another example of syntax for the DatastoreName?

    The example from Adias seems to have been removed.

    Eric