Sunday, 18 January 2009

Get-CountOfJerryShows.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Counts Jerry Garcia live shows on q: drive   
  4. .DESCRIPTION 
  5.     I store Jerry Garcia live shows on my Q: drive. This 
  6.     script counts the shows by year, and gives a total. 
  7. .NOTES 
  8.     File Name  : get-countofjerryshows.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell V2 CTP3 
  11. .LINK 
  12.     http://www.pshscripts.blogspot.com 
  13. .EXAMPLE 
  14.     PS C:\foo> .\get-countofjerryshows 
  15.     in: jg_1972_project,    9 shows 
  16.     in: jg_1973_project,   39 shows 
  17.     in: jg_1974_project,   40 shows 
  18.     in: jg_1975_project,   34 shows 
  19.     in: jg_1976_project,   52 shows 
  20.     in: jg_1977_project,   53 shows 
  21.     in: jg_1978_project,   27 shows 
  22.     in: jg_1979_project,   31 shows 
  23.     in: jg_1980_project,   56 shows 
  24.     in: jg_1982_project,   84 shows 
  25.     in: jg_1983_project,    3 shows 
  26.     in: jg_1984_project,   76 shows 
  27.     in: jg_1985_project,   22 shows 
  28.     in: jg_1986_project,   25 shows 
  29.     in: jg_1989_project,   32 shows 
  30.     in: jg_1990_project,    1 shows 
  31.     in: jg_1991_project,   64 shows 
  32.     in: jg_1992_project,   26 shows 
  33.     in: jg_1993_project,    5 shows 
  34.     in: jg_1994_project,   36 shows 
  35.     in: jg_1995_project,   19 shows 
  36.     734 shows in total 
  37. #> 
  38.  
  39. ## 
  40. # Start of Script 
  41. ## 
  42.  
  43. # Get starting point and move there 
  44.  
  45. $jerry = "q:\Jerry Garcia" 
  46. cd $jerry 
  47.  
  48. # Get sub-dirs that contain shows 
  49. $dirs = ls | where {$_.Name -match "jg_"
  50.  
  51. # Now iterate and count 
  52. $total = 0 
  53. foreach ($dir in $dirs) { 
  54.   $shows = ls $dir.FullName 
  55.   if ($shows.count) {$count=$shows.count} else {$count = 1} 
  56.   "In: {0,-15}, {1,4} shows" -f $dir.Name, $count 
  57.   $total += $count 
  58. "{0} shows in total" -f $total 

No comments: