Windows OS Hub
  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange

 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
How to Automatically Login in Windows 10 without Password?
next post
DistributedCOM Error 10016 in Windows: The Application-specific Permission Settings do not Grant Local Activation Permission

Related Reading

Windows 10: No Internet Connection After Connecting to...

January 13, 2021

Updating the PowerShell Version on Windows

December 24, 2020

Restoring Deleted Active Directory Objects/Users

December 21, 2020

Auditing Weak Passwords in Active Directory

December 14, 2020

Copy AD Group Membership to Another User in...

December 11, 2020

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
  • Windows 10
  • Windows 8
  • Windows 7
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2008 R2
  • PowerShell
  • VMWare
  • MS Office

Recent Posts

  • MS SQL Server 2019 Installation Guide: Basic Settings and Recommendations

    January 19, 2021
  • USB Device Passthrough (Redirect) to Hyper-V Virtual Machine

    January 15, 2021
  • Windows 10: No Internet Connection After Connecting to VPN Server

    January 13, 2021
  • Updating the PowerShell Version on Windows

    December 24, 2020
  • How to Enable and Configure User Disk Quotas in Windows?

    December 23, 2020
  • Restoring Deleted Active Directory Objects/Users

    December 21, 2020
  • Fix: Search Feature in Outlook is Not Working

    December 18, 2020
  • Zabbix: Single Sign-On (SSO) Authentication in Active Directory

    December 17, 2020
  • Preparing Windows for Adobe Flash End of Life on December 31, 2020

    December 15, 2020
  • Auditing Weak Passwords in Active Directory

    December 14, 2020

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Get-ADUser: Getting Active Directory Users Info via PowerShell
  • Install RSAT Feature on Demand on Windows 10 1809 and Later
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • Get-ADComputer: Find Computer Details in Active Directory with PowerShell
  • How to Create a UEFI Bootable USB Drive to Install Windows 10 or 7?
  • PowerShell: Get Folder Sizes on Disk in Windows
  • How to Find the Source of Account Lockouts in Active Directory domain?
Footer Logo

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


Back To Top