Created
July 13, 2015 16:08
-
-
Save equelin/3996e376d94e07ec9bf7 to your computer and use it in GitHub Desktop.
UNMAP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param ( | |
[Parameter(Mandatory=$true)] | |
[string]$VMHost, | |
[string]$Datastore="*", | |
[int]$asyncUnmapFilePourcentage=50 | |
) | |
# Récupere les informations sur le ou les datastore(s) | |
$Datastores = Get-Datastore -Name $Datastore | |
# Réclamation de l'espace libre sur chaque datastore | |
foreach ($DS in $Datastores) { | |
#Calcul de la taille du fichier asyncUnmapFile en fonction du pourcentage passé en argument. Par défaut 50% | |
[int]$FreeSpace = $DS.FreeSpaceMB | |
$asyncUnmapFileSize = [math]::Round($FreeSpace / $asyncUnmapFilePourcentage) | |
# Esxcli | |
$esxcli = get-vmhost -Name $VMHost | Get-EsxCli | |
Write-Host "Reclamation de l'espace libre sur $($DS.name) par bloc de $asyncUnmapFileSize Mo et depuis le serveur $VMHost" | |
#Execution de la commande avec gestion des erreurs | |
Try { | |
$result = $esxcli.storage.vmfs.unmap($asyncUnmapFileSize, $DS.name, $null) | |
} | |
Catch [VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.ViError] { | |
Write-Host "Erreur lors de la réclamation de l'espace libre sur $($DS.name)" | |
Write-Host $_.Exception.Message | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment