Archive

Archive for the ‘Find large files on disk’ Category

Find large files on disk

November 11, 2014 Leave a comment

How to find large files on a disk ?

The script will search the large files as per defined file size. The script has 2 input parameters

param([string]$SearchPath,[String] $FileSize)

[string]$SearchPath : Pass the drive path , drive letter or leave it blank (example : C:\xyz\… , C:\,” “)

[String] $FileSize : Search file of size greater than (example : 1024GB or 1024MB)


param([string]$SearchPath,[String] $FileSize)
$CurrentDate=Get-Date
Write-Host `n "Search Start Time : "  $CurrentDate -ForegroundColor Yellow
    if($SearchPath -eq " ")
        {
            foreach ($drive in (Get-PSDrive -PSProvider FileSystem))
            {                
                $DriveName=$drive.Name+":\"
                if ((Test-Path -Path $DriveName) -eq "True")
                {Get-ChildItem $DriveName -Recurse -Force -ErrorAction Ignore | Where-Object {$_.Length -gt $FileSize}| `
                 SELECT Name,@{Name="FileSize[GB]";Expression={[math]::Round($_.Length / 1GB)}},LastWriteTIme `
                 -ErrorAction SilentlyContinue | Format-Table -AutoSize
                }
            }
        }
    else
        {        
            if ((Test-Path -Path $SearchPath) -eq "True")
                {Get-ChildItem $SearchPath -Recurse -Force -ErrorAction Ignore | Where-Object {$_.Length -gt $FileSize}| `
                 SELECT Name,@{Name="FileSize[GB]";Expression={[math]::Round($_.Length / 1GB)}},LastWriteTIme ` 
                 -ErrorAction SilentlyContinue | Format-Table -AutoSize
                }
        }
$CurrentDate=Get-Date
Write-Host `n "Search End Time : "  $CurrentDate -ForegroundColor Yellow

image