Creating Clone of Virtual Machine from PowerShell

During the previous articles, we created a virtual machine and installed an operating system on it, that we intend to use as base image for automatically generating environment for tests. In case you missed those articles, here is the research plan for automatic test environments.

Now that we created the image, we would like to create a clone of it. We plan to do this in PowerShell, so that we can easily add it later to Jenkins for automation. The first step is creating the image for importing and in this way, we can also archive it. I used the following parameters that you should replace with yours:

  • Virtual Machine name: ate-windows-base
  • Path for storing images: D:\ate\images

To import a clone of the virtual machine we should do the following, with consideration that there are parameters in the command:

  • D:\ate\images\ate-windows-base\Virtual Machines directory is created by the previous command, and the vmcx file probably has different GUID in your environment.
  • I decided to store the clone under D:\working-images\img001 and its hard disks under a subdirectory of it called Virtual Hard Disks.

After importing the image, we will have a duplicate named virtual image in the Hyper-V manager. To take care of that, let’s rename it.

You can connect with me on LinkedIn, Twitter or you can register on the blog. Share if you found this article useful or know somebody who would benefit from reading it.

By subscribing to the email list, you will be notified about new posts.
Loading

No comments yet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Powered by WordPress. Designed by WooThemes