Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d087fa747 | ||
|
|
a27c9a1607 |
@@ -0,0 +1,43 @@
|
||||
param(
|
||||
[string]$Path,
|
||||
[switch]$Recurse,
|
||||
[switch]$IncludeHidden,
|
||||
[Parameter(ParameterSetName="largest")][int]$Largest,
|
||||
[Parameter(ParameterSetName="smallest")][int]$Smallest,
|
||||
[string]$Units,
|
||||
[int]$Precision=2
|
||||
)
|
||||
|
||||
# If no path is specified, set $Path to the directory containing user profiles
|
||||
If (-not $Path ) {
|
||||
$Path = (Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' -Name ProfilesDirectory)
|
||||
$Recurse = $true
|
||||
$IncludeHidden = $false
|
||||
}
|
||||
|
||||
# Change the sort order depending on which parameter set was specified
|
||||
Switch ( $PSCmdlet.ParameterSetName ) {
|
||||
"largest" { $SortOrder = $true ; $Quantity = $Largest }
|
||||
"smallest" { $SortOrder = $false ; $Quantity = $Smallest }
|
||||
}
|
||||
|
||||
# If $Units is specified, make sure it's a supported type and set the label and file size in the output
|
||||
If ( $Units ) {
|
||||
Switch ( $Units.ToUpper() ) {
|
||||
"KB" { $UnitLabel = "Kilobytes (KB)" ; $Divisor = 1KB }
|
||||
"MB" { $UnitLabel = "Megabytes (MB)" ; $Divisor = 1MB }
|
||||
"GB" { $UnitLabel = "Gigabytes (GB)" ; $Divisor = 1GB }
|
||||
"TB" { $UnitLabel = "Terabytes (TB)" ; $Divisor = 1TB }
|
||||
default {
|
||||
# TODO: Throw an error here because the units are not supported
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Specify default label and file size in the output
|
||||
Else { $UnitLabel = "Bytes" ; $Divisor = 1 }
|
||||
|
||||
# Get the file paths and sizes as specified
|
||||
Get-ChildItem $Path -Recurse:$Recurse -Force:$IncludeHidden -ErrorAction SilentlyContinue |
|
||||
Sort-Object -Descending:$SortOrder -Property Length |
|
||||
Select-Object -First $Quantity @{Name="File Path";Expression={$_.DirectoryName + '\' + $_.Name}}, @{Name=$UnitLabel;Expression={[Math]::Round($_.Length / $Divisor, $Precision)}}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user