Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save puiutucutu/ace2ec0b60906fbe7d00b6a1f5fded55 to your computer and use it in GitHub Desktop.

Select an option

Save puiutucutu/ace2ec0b60906fbe7d00b6a1f5fded55 to your computer and use it in GitHub Desktop.
[System.IO.DirectoryInfo] supports UNC paths natively (e.g., \\server\share\folder).
$path = "\\server\share\folder"
$topN = 20
[System.IO.DirectoryInfo]::new($path).EnumerateFiles("*", [System.IO.SearchOption]::AllDirectories) |
Sort-Object Length -Descending |
Select-Object -First $topN |
Select-Object FullName, @{Name="SizeMB"; Expression={[Math]::Round($_.Length / 1MB, 2)}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment