Fix Hyper-V compacted disk size comparison

Prior to this the code compares the length of the path, which of course
doesn't change.
This commit is contained in:
Ben Brown 2020-02-28 16:49:54 +00:00
parent 0cfcbd66ca
commit 0936f8bc03
1 changed files with 2 additions and 2 deletions

View File

@ -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