Monday 26 January 2009

Get-WMILocalTime.ps1

  1. <# 
  2. .SYNOPSIS 
  3.   Gets time from WMI and displays it   
  4. .DESCRIPTION 
  5.    This script gets Win32_LocalTime and then displays  
  6.    the details. 
  7. .NOTES 
  8.     File Name  : Get-WMILocalTime.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell V2 CTP3 
  11. .LINK 
  12.     Script posted to:
  13.     http://pshscripts.blogspot.com/2009/01/get-wmilocaltimeps1.html
  14.     MSDN Sample at:
  15.     http://msdn.microsoft.com/en-us/library/aa394590(VS.85).aspx
  16. .EXAMPLE 
  17.     [ps] c:\foo> .\Get-WMILocaltimeps1 
  18.     Day          : 26 
  19.     Day Of Week  : 1 
  20.     Hour         : 20 
  21.     Minute       : 59 
  22.     Month        : 1 
  23.     Quarter      : 1 
  24.     Second       : 53 
  25.     Week In Month: 5 
  26.     Year         : 2009 
  27. #> 
  28.  
  29. ### 
  30. # Start of Script 
  31. ## 
  32.  
  33. # Speficy computer and get Local Time 
  34. $Computer = "." 
  35. $times = Get-WmiObject Win32_LocalTime -computer $computer 
  36.  
  37. # Now display the result 
  38.  
  39. Foreach ($time in $times) { 
  40. "Day          : {0}"  -f $Time.Day 
  41. "Day Of Week  : {0}"  -f $Time.DayOfWeek 
  42. "Hour         : {0}"  -f $Time.Hour 
  43. "Minute       : {0}"  -f $Time.Minute 
  44. "Month        : {0}"  -f $Time.Month 
  45. "Quarter      : {0}"  -f $Time.Quarter 
  46. "Second       : {0}"  -f $time.Second  
  47. "Week In Month: {0}"  -f $Time.WeekInMonth  
  48. "Year         : {0}"  -f $Time.Year  
  49. # End of Script 

No comments: