gangstanthony

Daily Powershell Challenge - 3/12/16

Mar 12th, 2016
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://www.reddit.com/r/PowerShell/comments/4a64bv/daily_powershell_challenge_31216/
  2.  
  3. function Get-DuplicateDownloads ($comp = $env:COMPUTERNAME) {
  4.     dir \\$comp\c$\users -Directory | ? {test-path "$($_.FullName)\downloads"} | select -exp basename | % {
  5.         dir \\$comp\c$\users\$_\downloads\* -file | group {$_.basename -replace ' \([0-9]+\)$'} | ? count -gt 1 | % {
  6.             $_.group | group {(Get-FileHash $_.fullname).hash} | ? count -gt 1 | % {
  7.                 $_.group | sort name -Descending | select -Skip 1 -exp fullname
  8.             }
  9.         }
  10.     }
  11. }
  12.  
  13. Get-DuplicateDownloads -comp 'workstation2' | Remove-Item -WhatIf
Add Comment
Please, Sign In to add comment