PowerShell – list large files

#-------------[deklarations]--------------------------
#source

#logs
$reportLog='\\hostname\logs\lergeFiles-report.txt'
#params
$dirToCheck='f:\'
#-------------[functions]--------------------------

$largeFilesDirs = Get-ChildItem -Path $dirToCheck -Recurse -ErrorAction Continue | Where-Object {$_.Length -gt 100MB}

foreach($largeFileDir in $largeFilesDirs) {
    foreach($largeFiles in $largeFileDir) {
        foreach($largeFile in $largeFiles) {
            $largeFile.Name
            $largeFile.DirectoryName
            $largeFile.Length
                
            $largeFileRecord = $largeFile.DirectoryName + "," + $largeFile.Name + "," + $largeFile.Length
            
            $largeFileRecord >> $reportLog
        }
    }
}
#-------------krolaki.eu--------------------------

Leave a Reply

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