Bonjour,
Avec la facilité d'utilisation d'HyperV3 sous Windows 8, il est assez simple de monter un lab personnel basé sur des disques de référence contenant un OS, et des VM utilisant un disque de différenciation.
Pour mes besoins, j'ai développé un script qui permet de créer rapidement une VM en se basant sur ces disques, que vous pouvez adapter à vos besoins
Vous devez adapter les variables concernant l'environnement (une racine, un rép de disk et un de VM)
Le script prend en argument obligatoire le nom de la VM, et en optionnel le nombre de CPU et la RAM. Il recherche les disques qui ne sont pas de DIFF et vous demande d'en choisir un, idem pour les vSwitch.
Les VM sont crées en mémoire dynamique par défaut.
# BJDC-NEW-VM
#
# Create a new VM using a Diff VHD
#
# Author : Bruce JDC 20130312
Param(
[Parameter(Mandatory=$true,Position=0)]
[String] $vmname,
[Parameter(Position=1)]
[Int64] $vmproc = 1,
[Parameter(Position=2)]
[Int64] $vmmem = 512MB
)
import-module Hyper-V
# Default VM directories
$vmrootpath = "U:\VM\"
$vmdiskpath = $vmrootpath + "disk\"
$vmpath = $vmrootpath + "vm\"
# Create Diff Disk
$disk = Get-ChildItem -Recurse -LiteralPath $vmrootpath -Filter "*.vhd*" | Get-Vhd| where {$_.VhdType -ne "Differencing"}
$disk | select @{name="Index";expression={[array]::IndexOf($disk,$_)}},Path | Format-Table -AutoSize
while (($tmpindex = Read-Host "Choose Disk Index") -gt ($disk.count-1)) {
"Out of bound, choose a valid index"
}
$vmdisk = New-VHD -Path ($vmdiskpath + $vmname+'.vhdx') -ParentPath $disk[$tmpindex].Path -Differencing
# choose Swith
$vmswitch = Get-VMSwitch
$vmswitch | select @{name="Index";expression={[array]::IndexOf($vmswitch,$_)}},Name,SwitchType,NetAdapterInterfaceDescription | Format-Table -AutoSize
while (($tmpindex = Read-Host "Choose Switch Index") -gt ($vmswitch.count-1)) {
"Out of bound, choose a valid index"
}
# Create VM w/ Dynamic Memory
$vm = New-VM -Name $vmname -MemoryStartupBytes 1024MB -VHDPath $vmdisk.path -Path $vmpath -SwitchName $vmswitch[$tmpindex].name
$vm | Set-Vm -ProcessorCount $vmproc -MemoryStartupBytes $vmmem -DynamicMemory -MemoryMaximumBytes $vmmem
Si vous pensez utiliser ce script, voter pour (+1)!
-----------
Bruce Jourdain de Coutance http://brucejdc.blog.free.fr