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 Previous Command History in PowerShell Console

January 31, 2023

How to Install the PowerShell Active Directory Module...

January 31, 2023

Finding Duplicate E-mail (SMTP) Addresses in Exchange

January 27, 2023

How to Disable or Uninstall Internet Explorer (IE)...

January 26, 2023

How to Delete Old User Profiles in Windows?

January 25, 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

  • Configure User’s Folder Redirection with Group Policy

    February 3, 2023
  • Using Previous Command History in PowerShell Console

    January 31, 2023
  • How to Install the PowerShell Active Directory Module and Manage AD?

    January 31, 2023
  • Finding Duplicate E-mail (SMTP) Addresses in Exchange

    January 27, 2023
  • How to Delete Old User Profiles in Windows?

    January 25, 2023
  • How to Install Free VMware Hypervisor (ESXi)?

    January 24, 2023
  • How to Enable TLS 1.2 on Windows?

    January 18, 2023
  • Allow or Prevent Non-Admin Users from Reboot/Shutdown Windows

    January 17, 2023
  • Fix: Can’t Extend Volume in Windows

    January 12, 2023
  • Wi-Fi (Internet) Disconnects After Sleep or Hibernation on Windows 10/11

    January 11, 2023

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • How to Create a UEFI Bootable USB Drive to Install Windows 10 or 7?
  • 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
Footer Logo

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


Back To Top