Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / PowerShell / How to Find Large Files on Your Computer Using PowerShell

March 20, 2019 PowerShell

How to Find Large Files on Your Computer Using PowerShell

When the system warns you that free space on your local drive is running out, the first thing that the administrator does is trying to find all large files that occupy much space. To search for new files, you can use Windows Explorer (there are several pre-defined templates of searching by size), your favorite file manager or third-party tools. However, unlike PowerShell, all these tools require installation. Let’s consider the example of quick searching large files on your local computer drive using PowerShell.

You can use the Get-ChildItem cmdlet to list the files in a specific directory (including subfolders) and their sizes.The cmdlet can search files across the entire disk or in a specific folder (for example, in user profiles and any other folders).

Let’s list the 10 largest files on disk C:\:

Get-ChildItem c:\ -r| sort -descending -property length | select -first 10 name, Length

Depending on the disk size and the number of files on it, it may take some time to complete the command.

The –r (Recurse) key means that all subfolder will be searched recursively. You can restrict the check to a certain depth level using –Depth parameter. If you don’t specify the path, all subfolders of the current directory will be searched.

using Get-ChildItem to find top 10 large file on a computer

As you can see, we got the list of ten largest files on the disk sorted in the descending order.

Tip. When accessing some directories even with the administrator privileges, the Get-ChildItem cmdlet can return an access denied error:

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

To suppress such errors, use the -ErrorAction SilentlyContinue parameter.

Use the -Force option to display hidden and system files that are not accessible to the user.

Get-ChildItem : Access to the path is denied

As you can see, the file size is displayed in bytes. For convenience, they can be converted into megabytes. You can also display the folder, in which the found file is stored:

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

Script to find 10 largest files on a windows server or pc

The resulting table can be converted into a convenient graphic table using the Out-GridView cmdlet:

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

Get-ChildItem folder size Out-GridView

Similarly, you can find all files that are larger than a certain size, for example, 500 MB:

$size=500*1024*1024
GCi C:\ -recurse -ErrorAction SilentlyContinue –Force | where-object {$_.length -gt $size} | Sort-Object length | ft fullname

You can export the list of files into a CSV file as follows:

GCi C:\ -recurse | where-object {$_.length -gt $size} | Sort-Object length | ft fullname | Export-Csv c:\pc\LargeFiles_Report.csv

If you need to calculate the size of all files in a specific directory, read the article Calculating Folder Size with PowerShell.

2 comments
1
Facebook Twitter Google + Pinterest
previous post
Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
next post
DistributedCOM Error 10016 in Windows: The Application-specific Permission Settings do not Grant Local Activation Permission

Related Reading

Using PowerShell Behind a Proxy Server

July 1, 2022

Checking Windows Activation Status on Active Directory Computers

June 27, 2022

Configuring Multiple VLAN Interfaces on Windows

June 24, 2022

How to Disable or Enable USB Drives in...

June 24, 2022

FAQ: Licensing Microsoft Exchange Server 2019/2016

June 14, 2022

2 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

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows 7
  • Windows Server 2019
  • Windows Server 2016
  • Windows Server 2012 R2
  • PowerShell
  • VMWare
  • Hyper-V
  • MS Office

Recent Posts

  • Using PowerShell Behind a Proxy Server

    July 1, 2022
  • How to Access VMFS Datastore from Linux, Windows, or ESXi?

    July 1, 2022
  • How to Deploy Windows 10 (11) with PXE Network Boot?

    June 27, 2022
  • Checking Windows Activation Status on Active Directory Computers

    June 27, 2022
  • Configuring Multiple VLAN Interfaces on Windows

    June 24, 2022
  • How to Disable or Enable USB Drives in Windows using Group Policy?

    June 24, 2022
  • Adding Domain Users to the Local Administrators Group in Windows

    June 23, 2022
  • Viewing a Remote User’s Desktop Session with Shadow Mode in Windows

    June 23, 2022
  • How to Create a Wi-Fi Hotspot on your Windows PC?

    June 23, 2022
  • Configuring SSH Public Key Authentication on Windows

    June 15, 2022

Follow us

woshub.com

ad

  • Facebook
  • Twitter
  • RSS
Popular Posts
  • How to Find the Source of Account Lockouts in Active Directory domain?
  • Get-ADComputer: Find Computer Details in Active Directory with PowerShell
  • How to Create a UEFI Bootable USB Drive to Install Windows 10 or 7?
  • Adding Third-Party Drivers into VMWare ESXi 6.7 ISO Image
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • How to Delete Old User Profiles Using GPO and PowerShell?
  • Deploy PowerShell Active Directory Module without Installing RSAT
Footer Logo

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


Back To Top