From 642dfa4deba76f66497e610b76c97d89753a6586 Mon Sep 17 00:00:00 2001 From: Nicole Rappe Date: Wed, 14 Aug 2024 01:17:37 -0600 Subject: [PATCH] Update Scripts/Powershell/Hyper-V/Failover Cluster/Collapse Differencing Disk Chains.md --- .../Collapse Differencing Disk Chains.md | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Scripts/Powershell/Hyper-V/Failover Cluster/Collapse Differencing Disk Chains.md b/Scripts/Powershell/Hyper-V/Failover Cluster/Collapse Differencing Disk Chains.md index dc45724..b55bc01 100644 --- a/Scripts/Powershell/Hyper-V/Failover Cluster/Collapse Differencing Disk Chains.md +++ b/Scripts/Powershell/Hyper-V/Failover Cluster/Collapse Differencing Disk Chains.md @@ -1,5 +1,5 @@ ## Purpose -Sometimes things go awry with backup servers and Hyper-V and a bunch of extra `.avhdx` virtual differencing disks are created, taking up a ton of space. This can be problematic because if you run out of space, the virtual machines running on that underlying storage will stop working. Sometimes this can involve dozens or even hundreds of disk in rare cases that need to be manually merged or "collapsed" down to reclaim the lost space. +Sometimes things go awry with backup servers and Hyper-V and a bunch of extra `.avhdx` virtual differencing disks are created, taking up a ton of space. This can be problematic because if you run out of space, the virtual machines running on that underlying storage will stop working. Sometimes this can involve dozens or even hundreds of differencing disks in rare cases that need to be manually merged or "collapsed" down to reclaim the lost space. ## Powershell Script You need to copy the contents of the following somewhere on your computer and save it as `Get-HyperVParentDisks.ps1`. @@ -46,7 +46,7 @@ function Merge-DiskIntoParent { Write-Output "[Differential Disk $DiskNumber of $TotalDisks]" Write-Output "Child: $ChildDisk" Write-Output "Parent: $ParentDisk" - Write-Output "[Dry Run] Would merge child into parent" + Write-Output "[Dry Run] Would Merge Child into Parent" } else { Write-Output "[Differential Disk $DiskNumber of $TotalDisks]" Write-Output "Child: $ChildDisk" @@ -55,33 +55,33 @@ function Merge-DiskIntoParent { $childDiskInfo = Get-VHD -Path $ChildDisk if ($childDiskInfo.VhdFormat -ne 'VHDX' -or $childDiskInfo.VhdType -ne 'Differencing') { Write-Output "Error: $ChildDisk is not a valid differencing disk (AVHDX) and cannot be merged." - throw "Invalid disk type for merging." + throw "Invalid Disk Type for Merging." } Merge-VHD -Path $ChildDisk -DestinationPath $ParentDisk -Confirm:$false Write-Output "Successfully Merged Child into Parent" } catch { - Write-Output "Failed to merge ${ChildDisk} into ${ParentDisk}: $_" + Write-Output "Failed to Merge ${ChildDisk} into ${ParentDisk}: $_" Restart-Service -Name vmms - throw "Merge failed. Halting script." + throw "Merge failed. Halting Script." } } } -Write-Output "Starting parent disk search for: $AVHDXPath" +Write-Output "Starting Parent Disk Chain Search for: $AVHDXPath" $parentDiskChain = Get-AllParentDisksChain -CurrentDisk $AVHDXPath $totalDisks = $parentDiskChain.Count -Write-Output "Total parent disks found: $totalDisks" +Write-Output "Total Parent Disks Found: $totalDisks" if ($MergeIntoParents) { - Write-Output "`nStarting merge process..." + Write-Output "`nStarting Merge Process..." for ($i = 0; $i -lt ($totalDisks - 1); $i++) { $currentDisk = $parentDiskChain[$i] $nextDisk = $parentDiskChain[$i + 1] Merge-DiskIntoParent -ChildDisk $currentDisk -ParentDisk $nextDisk -DiskNumber ($i + 1) -TotalDisks $totalDisks } - Write-Output "Merge process completed." + Write-Output "Merge Process Completed." } elseif ($DryRun) { - Write-Output "[Dry Run] Merge simulation completed." + Write-Output "[Dry Run] Merge Simulation Completed." } ```