3

I am designing a testing infrastructure for a WPF application. I want a system that will create a VM when a new MSI appears in a folder, and install the MSI on the newly created VM. I am using Hyper-V and PowerShell. The folder watching and kickoff is all stuff I can do, but it's the Hyper-V aspect where I am stuck. I have a VM that I want to use as the base, but I don't know where to go from here.

Is it better to Export the VM, and then have the PS script Import/Copy the VM? Is it better to "copy" the VM directly? Should checkpoints come into play? Is there a better approach?

If anyone has a link to a resource that talks about doing automated VM/App configuration using PS, that would be awesome. I'm a developer, and so I don't know the go to places for things like this.

Thanks, Erick

Erick T
  • 191
  • 1
  • 4

1 Answers1

1

I have a VM that I want to use as the base, but I don't know where to go from here.

The "right answer" is to use Virtual Machine Templates in SCCVM although judging from the tone of your question I'm guessing you do not have SCCVM.

What you can do instead, although it will take substantially more time, is to build a master image VM, sysprep it and then use the resulting VHD for your subsequent virtual machines.

Assuming you have already backed up your master image (both prior and post sysprep) you could do something simple like this:

Copy-Item C:\Hyper-V\MasterImage\MasterImage_CDrive.vhdx C:\Hyper-V\$SpawnVM\$SpawnVM.vhdx
New-VM $SpawnVM -Path "C:\Hyper-V"
Add-VMDisk -VM $SpawnVM -ControllerId 0 -Lun 0 -Path "C:\Hyper-V\$SpawnVM\$SpawnVM.vhdx"


That PowerShell snippet should copy the the VHD from your master image, create a new VM and then attach it. There's probably oh so much more you want to do so I'm going to point you to Hyper-V Cmdlets in Windows PowerShell which is pretty dang full featured in Windows 8.1 / Windows Server 2012 R2. If you have specific questions later on, please feel free to bring them back.


Should checkpoints come into play?

Maybe. You can create new Virtual Machine from existing Checkpoints by Exporting a VM from a Checkpoint (I believe this merges the differencing disk and the parent disk so you don't save any time). Checkpoints should really just be reserved for temporary point in time restores:

Checkpoints are intended to provide a temporary backup when you need to restore a virtual machine to a previous state after a change, such as a system or application update. However, you should not use checkpoints for the permanent backup of the operating system, applications, or files.



I'm a developer, and so I don't know the go to places for things like this.

Please don't take this the wrong way but if you are doing anything serious with this process consider talking with your system administration team or hiring someone either on-premise or a contractor that has the relevant experience. A small book could be written on each of these topics. It might be fine for you to hack through some PowerShell to automate some development or testing VMs but this doesn't sound like a good road to start heading down for serious production stuff. Just a friendly word of caution... make sure your DevOps isn't all Dev and no Ops.

Hopefully this gets you started. If you are doing this with any regularity and volume in a Production environment you should give System Center 2012 R2 Virtual Machine Manager and System Center 2012 R2 Orchestrator a serious look.

  • Thanks! I've been looking into SCVMM, and it's too bad it requires a domain. I'm trying to build out a test VM test without involving IT for the moment. – Erick T Mar 02 '14 at 18:23
  • First, create VM Hyper-V using a ISO Windows 2016. Then, How-to **Install-WindowsFeature** and apps (chocolatey) using Remote Powershell, against Virtual Machine (Windows 2016) in Hyper-V (in Windows 10) ? – Kiquenet Aug 18 '22 at 18:30