Friday 31 December 2010

Count-GDDuplicate.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Finds duplicates in the GD archive – A script
  4.     for New Year’s eve! 
  5. .DESCRIPTION 
  6.  
  7. .NOTES 
  8.     File Name  : Count-GDDuplicate.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell V2 
  11. .LINK 
  12.     http://pshscripts.blogspot.com/2010/12/count-gdduplicateps1.html 
  13. .EXAMPLE 
  14.     Psh[Cookham8]>C:\foo\Count-GdDuplicate.ps1 
  15.     Count-GDDuplicate.ps1 - v 1.0.1 
  16.  
  17.     99 shows have duplicates 
  18.     109 shows are duplicates of others 
  19. #> 
  20.  
  21. ### 
  22. # Start of Script 
  23. ## 
  24.  
  25. # Constants: 
  26. # $GDDiskRoot    - where to find shows 
  27. # $DeadShowBase  - folder at top of gd shows 
  28.  
  29. $GDDiskRoot = "M:" 
  30. $DeadShowBase = $GDDiskRoot + "\gd" 
  31.  
  32. # Announce Ourselves 
  33. "DuplicateCount.ps1 - v 0.0.1" 
  34. "+---------------------------------+" 
  35. "! Find Duplicate Shows :  $DeadShowBase   !" 
  36. "+---------------------------------+" 
  37. "" 
  38. # Get start time 
  39. $starttime = Get-Date 
  40. set-strictmode -off 
  41.  
  42. # Get the Dead shows 
  43.  
  44. $Dir = ls $DeadShowBase | where {$_.psiscontainer} 
  45. $DeadShows = $Dir.count 
  46. if ($DeadSHows -le 0) {"no shows found - check constants"; return
  47.  
  48. # So here look for duplicates. 
  49.  
  50. $shows =@{} 
  51.  
  52. $j = 0 
  53. foreach ($show in $dir){ 
  54. $j++ 
  55. $showdate = $show.name.substring(0,10) 
  56. if ($shows.$showdate) { 
  57.   $shows.$showdate++ 
  58. }   
  59. else
  60.   $shows += @{$showdate=1} 
  61. }    
  62.  
  63.  
  64. $shows = $shows.getenumerator() | Sort name 
  65. $totaldups = 0 
  66. $totaldupshows = 0 
  67. foreach ($show in $shows){ 
  68.    if ($show.value -gt 1) { 
  69.      # "{1} copies of: {0}" -f  $show.name, $show.value 
  70.      $totaldups++    
  71.      $totaldupshows += $show.value - 1 # anything after the 1st is a dup 
  72.    } 
  73.  
  74. # Display Summary 
  75. "{0} shows have duplicates" -f $totaldups 
  76. "{0} shows are duplicates of others" -f $totaldupshows 
Technorati Tags:

No comments: