首页 > 系统服务 > 详细

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

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!