Wednesday 5 August 2009

Get-Thursday

  1. <# 
  2. .SYNOPSIS 
  3.     This script checks of a particular date in the past was a Thurday. 
  4. .DESCRIPTION 
  5.     This script creates a DateTime object set for 1st May, 2003. The 
  6.     script then check to see if that day is a Thursday then displays
  7.     the day of week for that date (which is a Thursday). This script
  8.     is a copy of the MSDN sample, written in PowerShell.   
  9. .NOTES 
  10.     File Name  : Get-Thursday.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell V2 CTP3 
  13. .LINK 
  14.     This script posted to: 
  15.         http://pshscripts.blogspot.com/2009/08/get-thursday.html
  16.     MSDN Sample posted at: 
  17.         http://msdn.microsoft.com/en-us/library/system.dayofweek(VS.71).aspx 
  18. .EXAMPLE 
  19.     PSH [C:\foo]: . 'E:\PowerShellScriptLib\System.DateTime\get-thursday.ps1' 
  20.     Is Thursday the day of the week for 5/1/2003?: True 
  21.     The day of the week for 5/1/2003 is Thursday. 
  22. #> 
  23.   
  24. ## 
  25. # Start of script 
  26. ## 
  27.   
  28. # Create a DateTime for the first of May, 2003. 
  29. $dt = New-Object System.DateTime 2003, 5, 1 
  30.   
  31. # Now - is it Thursday? 
  32. "Is Thursday the day of the week for {0:d}?: {1}" -f $dt,($dt.DayOfWeek -eq [system.DayOfWeek]::Thursday) 
  33. "The day of the week for {0:d} is {1}." -f $dt, $dt.DayOfWeek 
  34. # End of Script 

No comments: