search large files in the folders or network locations


Hi All,

If you want to search large files in the folders or network locations, below is the PowerShell code.

workflow DirectoryCheck {

param([string[]]$FileShares,[int] $days ,[int] $sizeinMB)

$t=(get-date).adddays(-$days)

foreach –parallel -throttlelimit $fileshare.count ($Fileshare in $FileShares)

{

$DirArr = @()

$DirArr = Get-ChildItem -Path $Fileshare -Recurse -Directory | ? {$_.lastwritetime -ge $t }

foreach –parallel -throttlelimit 50 ($dir in $DirArr)

{

Get-ChildItem -Path $dir.FullName -File | ?{ $_.Length/1MB -ge $sizeinMB}| sort Length -desc | select Name,fullname, length, lastwritetime -First 100 -ExcludeProperty PSSourceJobInstanceId,PSComputerName

}

}

}

directorycheck -FileShares "C:\work\","D:\work" -days 800 -sizeinMB 1 |Out-GridView

get-childitem works really slowly if you have network locations to check. Below is the more information on that

https://blogs.msdn.microsoft.com/powershell/2009/11/04/why-is-get-childitem-so-slow/

I will post one more optimized script in upcoming posts.

Regards,

Chaitanya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: