Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| powershell_usedspace [2020/07/17 12:18] – créée nekan | powershell_usedspace [2021/03/05 16:10] (Version actuelle) – nekan | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ~~CLOSETOC~~ | ||
| ====== Connaître l' | ====== Connaître l' | ||
| + | <label type=" | ||
| une petite fonction utile pour connaître l' | une petite fonction utile pour connaître l' | ||
| - | <sxh powershell><# | + | <sxh powershell> |
| + | { | ||
| + | <# | ||
| .SYNOPSIS | .SYNOPSIS | ||
| Affiche la taille d'un dossier. | Affiche la taille d'un dossier. | ||
| Ligne 19: | Ligne 21: | ||
| .PARAMETER HumanReadable | .PARAMETER HumanReadable | ||
| - | Renvoie l' | + | Renvoie l' |
| .EXAMPLE | .EXAMPLE | ||
| - | Display-FolderUsedSpace -Path " | + | Get-FolderUsedSpace -Path " |
| .OUTPUTS | .OUTPUTS | ||
| - | System.String, | + | PSCustomObject |
| .NOTES | .NOTES | ||
| Ligne 36: | Ligne 38: | ||
| Plus d' | Plus d' | ||
| #> | #> | ||
| - | + | ||
| - | # Paramètres | + | # Paramètres |
| - | param | + | param |
| - | ( | + | ( |
| - | [string]$Path = (Get-Location).Path, | + | [string]$Path = (Get-Location).Path, |
| - | [switch]$Recurse = $false, | + | [switch]$Recurse = $false, |
| - | [switch]$HumanReadable = $false | + | [switch]$HumanReadable = $false |
| - | ) | + | ) |
| - | + | ||
| - | # Initialisation des variables | + | # Initialisation des variables |
| - | $FileList = @() | + | $FileList = @() |
| - | $Size = 0 | + | $Size = 0 |
| - | + | $Unit = " | |
| - | # Création de la liste des fichiers | + | |
| - | $FileList = Get-ChildItem -Path $Path -include * -Recurse: | + | # Création de la liste des fichiers |
| - | + | $FileList = Get-ChildItem -Path $Path -include * -Recurse: | |
| - | # Calcul | + | |
| - | ForEach ($File in $FileList) | + | # Calcul |
| - | { | + | ForEach ($File in $FileList) |
| - | # Ajout de la taille du fichier dans le total | + | { |
| - | $Size += $File.length | + | # Ajout de la taille du fichier dans le total |
| - | } | + | $Size += $File.length |
| - | + | } | |
| - | # Affichage du résultat | + | |
| - | if ($HumanReadable) | + | |
| - | { | + | |
| # Calcul de la fraction | # Calcul de la fraction | ||
| $Factor = [int][math]:: | $Factor = [int][math]:: | ||
| - | # Sélection | + | # Traitement |
| - | switch | + | if ($HumanReadable) |
| { | { | ||
| - | 0 { | + | # Sélection de l' |
| - | $Unit = " | + | switch ($Factor) |
| + | { | ||
| + | 0 { | ||
| + | $Unit = " | ||
| + | } | ||
| + | 1 { | ||
| + | $Unit = " | ||
| + | } | ||
| + | 2 { | ||
| + | $Unit = " | ||
| + | } | ||
| + | 3 { | ||
| + | $Unit = " | ||
| + | } | ||
| + | default { | ||
| + | $Unit = " | ||
| + | } | ||
| } | } | ||
| - | 1 { | + | |
| - | $Unit = " | + | # Calcule de la taille lisible |
| - | } | + | if ($Unit -ne "B") |
| - | 2 { | + | { |
| - | $Unit = "MB" | + | $Divider |
| - | } | + | $Size = [math]:: |
| - | 3 { | + | |
| - | $Unit = "GB" | + | |
| - | } | + | |
| - | default { | + | |
| - | $Unit = " | + | |
| } | } | ||
| + | } | ||
| + | |||
| + | # Création des propriétés de l' | ||
| + | $Hash = [ordered]@{ | ||
| + | Path = $Path | ||
| + | Size = $Size | ||
| + | Unit = $Unit | ||
| } | } | ||
| - | # Affiche du résultat | + | # Affichage de l' |
| - | if ($Unit | + | New-Object PSObject |
| - | { | + | |
| - | Write-Host "$Size B" | + | |
| - | } | + | |
| - | else | + | |
| - | { | + | |
| - | $Divide = " | + | |
| - | $HumanReadableSize = [math]:: | + | |
| - | Write-Host " | + | |
| - | } | + | |
| - | } | + | |
| - | else | + | |
| - | { | + | |
| - | Write-Host $Size | + | |
| }</ | }</ | ||
| - | |||
| - | --- // | ||
| ~~DISCUSSION~~ | ~~DISCUSSION~~ | ||