Overblog
Editer l'article Suivre ce blog Administration + Créer mon blog

Force reinit VM for Windows 10 OSD Tests

Publié le par damcuvelier

Quand on fait des tests OSD avec des VM HyperV, si on veut lancer un test en se servant d'un iso à la place du boot PXE.
Parfois des infos restent en cache et on a des faux positifs ou des faux négatif.
Et ça fausse les résultats car les VM ne se réinitialisent pas ou pas complètement.

When doing OSD tests with HyperV VMs, if we want to run a test using an iso instead of the PXE boot.
Sometimes information remains in cache and we have false positives or false negatives.
And it skew the results because the VMs do not reset or not completely.

Voici un bout de code powershell (admin) pour corriger ça, à lancer avant chaque nouveau test:
Here is a powershell block (admin) to correct this, to run before each new test:

HyperV PS1 Script Block:

$VhdsPath = "<Path to folder where a store the VHDX files>"
$VHdSize = "<Dynamic Size VHDX files>"
if(! $VHdSize){$VHdSize = 127GB}
$isopath = "<Path to iso file>"
$vm = "<Name of the VM or part of Name of the VM>"

$erroractionpreference = 'silentlycontinue'
set-executionpolicy bypass -force
$vmName = (Get-VM | where-object{$_.Name -match $vm}).Name
$VMvhdpath = "$VhdsPath\$vm.vhdx"
cmd /c "del /F /Q $VMvhdpath"
New-VHD -Path $VMvhdpath -SizeBytes $VHdSize -Dynamic
Get-VMDvdDrive -VMName $vmName | Remove-VMDvdDrive
Add-VMDvdDrive -VMName $vmName -Path $isopath
# $vm = "TSTVM1"
$vmName = (Get-VM | where-object{$_.Name -match $vm}).Name
Get-VMFirmware -VMName $vmName |ForEach-Object {Set-VMFirmware -BootOrder ($_.Bootorder | Where-Object {$_.BootType -notmatch 'File'}) $_ }
Get-VMFirmware -VMName $vmName |ForEach-Object {Set-VMFirmware -BootOrder ($_.Bootorder | Where-Object {$_.BootType -notmatch 'Network'}) $_ }
$VMDvdDrive = Get-VMDvdDrive -VMName $vmName
$vmHardDiskDrive = Get-VMHardDiskDrive -VMName $vmName
Set-VMFirmware -VMName $vmName -BootOrder $VMDvdDrive, $vmHardDiskDrive 

 

Puis démarrer la VM qui partira bootera directement sur l'ISO ($isopath).
Then start the VM which will boot directly on the ISO ($isopath).

Commenter cet article