Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • 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 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

February 20, 2023 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

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

How to Query and Change Teams User Presence...

October 8, 2023

Installing Language Pack in Windows 10/11 with PowerShell

September 15, 2023

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 Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • Deploy PowerShell Active Directory Module without Installing RSAT
  • Managing User Photos in Active Directory Using ThumbnailPhoto Attribute
  • RDP Brute Force Protection with PowerShell and Windows Firewall Rules
  • Active Directory Dynamic User Groups with PowerShell
  • Match Windows Disks to VMWare VMDK Files
  • Auditing Weak Passwords in Active Directory
Footer Logo

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


Back To Top