add script

This commit is contained in:
2025-08-06 10:35:05 +02:00
parent b78e202f58
commit ef09f0b350
229 changed files with 264140 additions and 1 deletions

26
Hyper-V/Compact-VHD.ps1 Normal file
View File

@@ -0,0 +1,26 @@
# Importer le moudule Hyper-V
Import-Module -Name Hyper-V
# Chemin du VHD et mode de compactage
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)][String]$Path,
[Parameter()][Microsoft.Vhd.PowerShell.VhdCompactMode]$Mode = [Microsoft.Vhd.PowerShell.VhdCompactMode]::Full
)
# Vérifier le fichier
try {
$Path = (Resolve-Path -Path $Path -ErrorAction Stop).Path
if ($Path -notmatch '\.a?vhdx?$') { throw }
}
catch {
throw('{0} is not a valid VHDX file.' -f $Path)
}
# Monter le VHD
Mount-VHD -Path $Path -ReadOnly -ErrorAction Stop
# Compacter le VHD
Optimize-VHD -Path $Path -Mode $Mode -ErrorAction Continue
# Démonter le VHD
Dismount-VHD -Path $Path