-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMergeAVHDX.ps1
30 lines (21 loc) · 1.15 KB
/
MergeAVHDX.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Path to AVHDX
$PathToVHDX = "C:\ClusterStorage\SPT-CSV-016-7C-ST-PU-120-SM\60c96f8df8f542abb44832b14e3007e8\Ide0-0"
$AlleFiles = Get-ChildItem -path $PathToVHDX
$AlleFiles = $AlleFiles | Sort-Object LastWriteTime
## Filter on avhdx and select the youngest
$LatestAHVDX = $AlleFiles | Where-Object { $_.Name -like "*.avhdx" } | Sort-Object LastWriteTime -Descending | Select-Object -First 1
While ( $LatestAHVDX.count -gt 0)
{
## ## Filter on avhdx and select the youngest
Write-host "Youngest AVHDX = $($LatestAHVDX.Name) - $($LatestAHVDX.LastWriteTime)"
# Merge youngest AVHDX into VDX
$Source = $($PathToVHDX + "\" + $($LatestAHVDX.Name))
$VHDSource = get-vhd $Source
write-host "Merge: $source to $($VHDSource.ParentPath)"
Merge-VHD -Path $Source -DestinationPath $VHDSource.ParentPath
$AlleFiles = Get-ChildItem -path $PathToVHDX
$AlleFiles = $AlleFiles | Sort-Object LastWriteTime
Write-host "Number of files: $($AlleFiles.count)"
## ## Filter on avhdx and select the youngest
$LatestAHVDX = $AlleFiles | Where-Object { $_.Name -like "*.avhdx" } | Sort-Object LastWriteTime -Descending | Select-Object -First 1
}