AftabHussain

get-largeFiles

Aug 4th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Original by martijnaa (https://www.reddit.com/user/martijnaa)
  2. ## https://www.reddit.com/r/PowerShell/comments/3fqtlk/simple_script_look_for_large_files/
  3. ## 04/08/2015
  4.  
  5. Function Get-LargeFiles {
  6.  
  7. Param (
  8.     [parameter(Mandatory=$true)]
  9.     [long]$size,
  10.     [parameter(Mandatory=$true)]
  11.     [ValidateScript({Test-Path $_ -PathType 'Container'})]
  12.     [string]$location,
  13.     [parameter(Mandatory=$false)]
  14.     [ValidateScript({Test-Path $_ -IsValid})]
  15.     [string]$export
  16. )
  17.  
  18.     $results = Get-ChildItem "$location\" -Recurse | Where-Object {$_.Length -gt $size} | Select FullName, @{Name="Size(MB)";Expression={"{0:N1}" -f($_.Length/1MB)}} | Sort-Object "Size(MB)" -desc
  19.  
  20.     If ($export) {
  21.         $results | Export-csv $export -NoTypeInformation
  22.     }
  23.     Else {
  24.         $results
  25.     }
  26. }
  27.  
  28. Get-LargeFiles -size 100MB -location C:\folder-with-large-files -export E:\largefiles.csv
Add Comment
Please, Sign In to add comment