Skip to content

Instantly share code, notes, and snippets.

@atzimler
Created June 4, 2017 12:07
Show Gist options
  • Save atzimler/41e1ea95c29552e03a0c77687f10f2b8 to your computer and use it in GitHub Desktop.
Save atzimler/41e1ea95c29552e03a0c77687f10f2b8 to your computer and use it in GitHub Desktop.
$TemplateDirectory = $env:TEMPLATE_DIRECTORY
$ImageDirectory = $env:IMAGE_DIRECTORY
$Image = $env:IMAGE
$Template = $env:TEMPLATE
$vmcx = ls "$TemplateDirectory\$Template\Virtual Machines\*.vmcx"
$path = "$TemplateDirectory\$Template\Virtual Machines\" + $vmcx.Name
$vmpath = "$ImageDirectory\$Image"
Import-VM -Path $path -Copy -GenerateNewId -VirtualMachinePath $vmpath -VhdDestinationPath "$vmpath\Virtual Hard Disks"
$vm = Get-VM | Where {$_.Path.StartsWith($vmpath)}
Rename-VM $vm -NewName $Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment