Hyper-V PowerShell creates a virtual machine based on a differencing disk

Source: Internet
Author: User

$imageAll =get-childitem "D:\Hyper-V\master image" #the path of the parent VHD images
# $imageAll [0]. FullName
$i =1
#list all of the parent VHD images
foreach ($image in $imageAll)
{
Write-host "Type of OS" $i ($image)
$i + +
}

$typeOS =read-host "Please Input the type of OS"
$ParerentPath = $imageAll [$typeos-1]. FullName

$vmName =read-host "Please Input the VM Name"
$k =1
while ($k-eq 1)
{
if (GET-VM |? name-eq $vmname)
{
echo "The VM existed!"
$vmName =read-host "Please Input the VM Name"
$k =1
}
else {$k = 0}
}

$vhdpath = "D:\Hyper-V\Virtual hard disks\" + $vmName + ". Vhdx"

# $vhdsize = 300GB


New-vhd–parentpath $ParerentPath –path $vhdpath-differencing #create diffencing VHD

$switch = "Inside" #set VM connecting to Inside Vswitch

#create New VM
New-vm–name $vmName-generation 2–memorystartupbytes 1gb–vhdpath $vhdpath-switchname $switch

#setting the VM
SET-VM $vmName-dynamicmemory-memorymaximumbytes 4gb-automaticstartaction Nothing

Hyper-V PowerShell creates a virtual machine based on a differencing disk

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.