Clone-VMFromSnapshot

This is a function that allows you to clone a VM from a specified snapshot. The only way to do this in the UI would be to take a snapshot of the current state, revert to the one you wish to clone, clone, revert to latest snapshot and then delete latest snapshot. As you can see that is time consuming and takes numerous mouse clicks.

I recommend adding this function to your powershell profile so you always have access to it.

As always feel free to comment.

Download

2 thoughts to “Clone-VMFromSnapshot”

  1. The script should be fairly easy to modify to accommodate that.

    In the script there is a line:
    $cloneFolder = $vm.parent

    If you add a parameter that if specified sets $cloneFolder then the clone will be created in that folder.

    Something like this should do the trick:
    In the param section add
    [String] $DstFolder

    then replace the line $cloneFolder = $vm.parent with

    if ($DstFolder) {
    $cloneFolder = (Get-Folder -Name $DstFolder).Id // use only if the folder name is unique.
    } else {
    $cloneFolder = $vm.parent
    }

    If the folder name is not unique then you will need to implement something like the following in the middle of the code.

    http://www.lucd.info/2010/10/21/get-the-folderpath/

    and restrict by path.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This blog is kept spam free by WP-SpamFree.