From 0936f8bc034e224b40a2a0197940456b239925d1 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Fri, 28 Feb 2020 16:49:54 +0000 Subject: [PATCH] Fix Hyper-V compacted disk size comparison Prior to this the code compares the length of the path, which of course doesn't change. --- common/powershell/hyperv/hyperv.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/powershell/hyperv/hyperv.go b/common/powershell/hyperv/hyperv.go index a80624609..363701d1f 100644 --- a/common/powershell/hyperv/hyperv.go +++ b/common/powershell/hyperv/hyperv.go @@ -872,9 +872,9 @@ if ($disks.Length -eq 0) { foreach ($disk in $disks) { Write-Output "Compacting disk: $(Split-Path $disk -leaf)" - $sizeBefore = $disk.Length + $sizeBefore = (Get-Item -Path $disk).Length Optimize-VHD -Path $disk -Mode Full - $sizeAfter = $disk.Length + $sizeAfter = (Get-Item -Path $disk).Length # Calculate the percentage change in disk size if ($sizeAfter -gt 0) { # Protect against division by zero