码迷,mamicode.com
首页 > 系统相关 > 详细

Hyper-v powershell 基于差异盘创建虚拟机

时间:2017-03-14 21:42:59      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:powershell   hyper-v   new-vm   创建虚机   

$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 基于差异盘创建虚拟机

标签:powershell   hyper-v   new-vm   创建虚机   

原文地址:http://pclzr.blog.51cto.com/30415/1906332

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!