Windows- PowerShell – Script to List the Files in a Directory with File size in GB and Date condition

This is powershell script to list the files with size in GB which is older than 15 days. In this case, I had run this script in the D:\ drive.

get-childitem -Recurse -File|sort -descending -Property length | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-15)} | select name,lastwritetime,@{Name="Gigabytes";Expression={[Math]::round($_.length / 1GB, 2)}}

If you want to export the details to csv, use the following command

get-childitem -Recurse -File|sort -descending -Property length | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-15)} | select name,lastwritetime,@{Name="Gigabytes";Expression={[Math]::round($_.length / 1GB, 2)}} | Export-csv -path D:\Backups\space.csv

 

print

Leave a Reply

Your email address will not be published. Required fields are marked *


seven + 5 =