Home » PowerShell Tips » PowerShell-Find Large Size Files

PowerShell-Find Large Size Files

Most of the time as a System administrator, we have to monitor file size on specified location to find large size files and take necessary action. In PowerShell, using Get-ChildItem cmdlet to get items in one ore more specific location and file size attribute to find large size files.

In this article, I will explain you about how to use PowerShell Get-ChildItem cmdlet to find large size files to take necessary actions.

PowerShell Find Large Size Files

Using PowerShell Get-ChildItem cmdlet to find large size files in current folder. Run below command

Get-ChildItem -File | Where-Object {$_.Length -gt 52428800} | Select Name, CreationTime,Length 

In the above PowerShell script, Get-ChildItem cmdlet gets file objects as specified by -File parameter and pass its output to second command.

Second command finds file size larger than 50mb and pass its output to third command.

Third command select file name, file creation time and file size specified by Length and list all files on PowerShell console.

PowerShell Delete Files Size if Greater than Specific Size

Use Get-ChildItem to get items and find size greater than specific size in directory. If file size is greater than specific size it will delete files using Remove-Item

Get-ChildItem -Recurse -File| Where-Object {$_.Length -gt 2775000} | ?{Remove-Item $_.fullname}

In the above PowerShell script, Get-ChildItem cmdlet gets file object and pass its output to second command.

Second command search for file size is greater than specific size ( 27775000 bytes) and pass its output to third command.

Third command use Remove-Item cmdlet to delete large size files than specific size.

Cool Tip: How to count files in folder using Get-ChildItem in PowerShell!

Conclusion

I hope above article on how to find large size files in PowerShell using Get-ChildItem cmdlet and delete file size larger than specific size using Remove-Item cmdlet.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Leave a Comment