Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / PowerShell / How to Find Large Files on a Computer with PowerShell

September 26, 2024

How to Find Large Files on a Computer with PowerShell

To find large files on a computer, you can use Windows File Explorer, one of the third-party tools (such as WinDirStat or TreeSize), or your favorite file manager. In some cases, it is more convenient to use PowerShell commands to quickly find large files on a computer because there is no need to install third-party tools.

For example, to list the 10 largest files on a particular drive, run the following PowerShell command

Get-ChildItem -Path c:\ -Recurse –Force| sort -descending -property length | select -first 10 FullName, Length

After some time (depending on the size of the partition and the number of files), the command will return a list of the 10 largest files, sorted by size.

find top 10 large files on a computer using powershell

The Get-ChildItem cmdlet is used to get a list of files in a directory (or you can use one of the aliases: ls , dir or gci ). The following parameters are used in the above command to find large files::

  • -Path C:\ — path to the directory to search files. You can perform a full disk search or a folder search (for example, in a user profile or shared folder). If the path is not specified, the current directory is searched. The -Path parameter allows to specify multiple folders and drive letters to search (separated by commas): -Path C:\,G:\,D:\IS0,F:\Downloads
  • -Recurse – this option indicates that a recursive search should be performed in all subdirectories. To restrict the folder search to a certain depth level, use the -Depth parameter.
  • -Force – option is used to include hidden folders and system folders (files) in the search (which are ignored by default).
  • Sort -descending -property Length – sort files by size in descending order (by the Length property).
  • Select FullName, Length – show the full path to the file and its size.
  • -first 10 – list the first 10 files only.
Tip. Even if you have administrative privileges, the cmdlet might return an access error when it tries to access some system directories:

Get-ChildItem : Access to the path 'C:\Windows\CSC' is denied.
At line:1 char:1
+ Get-ChildItem c:\ -r| sort -descending -property length | select -fir ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Windows\CSC:String) [Get-ChildItem], UnauthorizedAccessException
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

Add the -ErrorAction SilentlyContinue parameter to the Get-ChildItem command to suppress these errors.

Get-ChildItem : Access to the path is denied

By default, the Get-ChildItem cmdlet displays file sizes in bytes. Change the command as follows to convert them to gigabytes (GB):

Get-ChildItem c:\ -r -Force -ErrorAction SilentlyContinue |sort -descending -property length | select -first 10 name, DirectoryName, @{Name="GB";Expression={[Math]::round($_.length / 1GB, 2)}}

PowerShell: show large file size in GBs

The resulting list of large files can be converted into a convenient graphical table using the Out-GridView cmdlet:

Get-ChildItem c:\ -r -Force -ErrorAction SilentlyContinue |sort -descending -property length | select -first 10 name, DirectoryName, @{Name="GB";Expression={[Math]::round($_.length / 1GB, 2)}} | Out-GridView

Get-ChildItem folder size Out-GridView

Find all files on a hard drive larger than 10GB and export the list to a CSV file:

GCi C:\ -Recurse -Force -ErrorAction SilentlyContinue | where-object {$_.length -gt 10GB} | Sort-Object length | ft fullname,length| Export-Csv c:\pc\LargeFiles_Report.csv

Certain file types can be included or excluded from the search scope using the -Include and -Exclude options. For example, exclude files with SYS and VMDK extensions from the output:

Get-ChildItem G:\ -Exclude "*.sys","*.vmdk" -Recurse -Force -ErrorAction SilentlyContinue| sort -descending -property length | select -first 10 FullName, Length

To retrieve only files that match some filter criteria, use the -Filter option. For example, -Filter "*image*".

You can search for large files on a remote computer. In this case, specify the UNC path to a shared folder as the Get-ChildItem parameter (it is possible to specify the UNC path to the admin shares C$, D$ on a remote computer):

Get-ChildItem -Path \\PC123\C$ -Recurse |where-object {$_.length -gt 10GB} |sort -descending -property length | select -first 10 FullName, Length

Or, use the Invoke-Command cmdlet to get a list of the largest files on multiple computers:

$ComputerList = @("server1","server2")
Invoke-Command -ComputerName $ComputerList -ScriptBlock {gci -Path C:\ -r| sort -descending -property length | select -first 10 name, length}

3 comments
5
Facebook Twitter Google + Pinterest
PowerShell
previous post
Managing Printers and Drivers on Windows with PowerShell
next post
FTP Server Quick Setup on Windows 10/11 and Windows Server

Related Reading

How to Get My Public IP Address with...

October 24, 2023

Generating Strong Random Password with PowerShell

January 31, 2020

How to See Number of Active User Sessions...

March 16, 2024

Disks and Partitions Management with Windows PowerShell

March 11, 2024

Fix: DNS Resolution over VPN Doesn’t Work on...

December 27, 2023

How to Create and Use a RAM Drive...

December 18, 2023

FTP Server Quick Setup on Windows 10/11 and...

March 16, 2024

Transferring/Seizing FSMO Roles to Another Domain Controller

March 15, 2024

3 comments

Leoš Marek April 2, 2019 - 7:52 am

You have a typo in the code GCi C:\ -recurse -ErrorAction –Force SilentlyContinue. The -Force should be after SilentlyContinue

Reply
admin April 3, 2019 - 5:59 am

Thank you mate. I will fix it.

Reply
murat handan December 3, 2024 - 12:28 pm

sadece dosyalarımı mı buluyor? mesela beni bir dizinim var c:\dvnm12 bunun içinde yüzlerce dosya var ama bunu bulmuyor çünkü tek dosya yok

Does it only find my files? For example, I have a directory c:\dvnm12 which contains hundreds of files but it does not find it because there is not a single file

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Managing Printers and Drivers on Windows with PowerShell
  • Protecting Remote Desktop (RDP) Host from Brute Force Attacks
  • How to Set a User Thumbnail Photo in Active Directory
  • Implementing Dynamic Groups in Active Directory with PowerShell
  • Match Windows Disks to VMWare VMDK Files
  • How to Measure Storage Performance and IOPS on Windows
  • Disks and Partitions Management with Windows PowerShell
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top