Saturday, 18 September 2010

Get-ColourRGB.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the Windows Color dialog box, then 
  4.     displays the r, g, b values of the colours selected  
  5. .DESCRIPTION 
  6.     This script calls windows.forms to show the color dialog. You then  
  7.     select a colour, and hit OK. The script then displays the values you selected. 
  8. .NOTES 
  9.     File Name  : Get-ColourRGB.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://pshscripts.blogspot.com/2010/09/get-colourrgbps1.html 
  15. #> 
  16.  
  17. # Define worker function 
  18. function Get-ColourRGB { 
  19. param
  20. $R = 0,   # Red value 
  21. $G = 0,   # Green value 
  22. $B = 0    # Blue value 
  23. )   
  24.  
  25. # Show colour dialog, get colour  
  26. $colorDialog = New-Object Windows.Forms.ColorDialog -Property @{ 
  27.                FullOpen = $true 
  28.                Color = [Drawing.Color]::FromArgb($R,$G,$B
  29.                } 
  30.      
  31. if ($colorDialog.ShowDialog() -eq "OK") { 
  32.            $R = $colordialog.color.R 
  33.            $G = $colordialog.color.G 
  34.            $B = $colordialog.color.B 
  35.            $R;$G;$B  
  36.     }  
  37.  
  38. # Call the worker function 
  39. $R1,$G1,$B1 = Get-ColourRGB 128 128 128 
  40.  
  41. # Describe  
  42. " You set:" 
  43. " R to: {0}" -f $R1 
  44. " G to: {0}" -f $G1 
  45. " B to: {0}" -f $B1 

Friday, 17 September 2010

Get-ArrayList2.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates using an ArrayList 
  4. .DESCRIPTION 
  5.     This script re-implements an MSDN Sample using  
  6.     a System.Collection.ArrayList 
  7. .NOTES 
  8.     File Name  : Get-Arraylist2.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com 
  14.     MSDN sample posted tot: 
  15.         http://msdn.microsoft.com/en-us/library/system.collections.arraylist.insert.aspx 
  16. .EXAMPLE 
  17.     Left as an exercise for the reader! 
  18.      
  19. #> 
  20. $myAL = New-Object system.Collections.ArrayList 
  21. $myAL.Insert( 0, "The"
  22. $myAL.Insert( 1, "fox"
  23. $myAL.Insert( 2, "jumps"
  24. $myAL.Insert( 3, "over"
  25. $myAL.Insert( 4, "the"
  26. $myAL.Insert( 5, "dog"
  27.  
  28. # Create and initializes a new Queue. 
  29. $myQueue = New-Object system.Collections.Queue 
  30. $myQueue.Enqueue( "quick"
  31. $myQueue.Enqueue( "brown"
  32.  
  33. # Displays the ArrayList and the Queue. 
  34. "The ArrayList initially contains the following:" 
  35. $myAL 
  36. "The Queue initially contains the following:" 
  37. $myQueue 
  38.  
  39. # Copy the Queue elements to the ArrayList at index 1. 
  40. $myAL.InsertRange( 1, $myQueue
  41.  
  42. # Displays the ArrayList. 
  43.  "After adding the Queue, the ArrayList now contains:"  
  44.  $myAL 
  45.   
  46.  # Search for "dog" and add "lazy" before it. 
  47.  $myAL.Insert( $myAL.IndexOf( "dog" ), "lazy"
  48.  
  49. # Display the ArrayList. 
  50. "After adding `"lazy`", the ArrayList now contains:"  
  51. $myAL 
  52.  
  53. # Add "!!!" at the end. 
  54.  $myAL.Insert( $myAL.Count, "!!!"
  55.   
  56. # Display the ArrayList. 
  57. "After adding `"!!!`", the ArrayList now contains:" 
  58. $myAL 
  59.  
  60. # Inserting an element beyond Count throws an exception. 
  61. try  { 
  62.      $myAL.Insert( $myAL.Count+1, "anystring"
  63.       }  
  64. catch { 
  65. "Exception: " + $Error[0] 
  66.       } 

Thursday, 16 September 2010

Get-ArrayList.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates the use of the Systems.Collections.Arraylist class 
  4. .DESCRIPTION 
  5.     This script is a re-write of an MSDN sample script 
  6. .NOTES 
  7.     File Name  : get-arraylist.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://pshscripts.blogspot.com/2010/09/get-arraylistps1.html 
  13.     MSDN sample posted tot: 
  14.         http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\Get-ArrayList.ps1 
  17.     0 
  18.     1 
  19.     2 
  20.     myAL 
  21.     Count       : 3 
  22.     Capacity    : 4 
  23.     Fixed Len?  : False 
  24.     Read only?  : False 
  25.     Values   : 
  26.     Hello 
  27.     World 
  28.     ! 
  29. #> 
  30.  
  31. # Creates and initializes a new ArrayList. 
  32. $myAL = New-Object System.Collections.ArrayList 
  33.  
  34. # Add three values 
  35. $myAL.Add("Hello"
  36. $myAL.Add("World"
  37. $myAL.Add("!"
  38.  
  39. # Display the properties and values of the ArrayList. 
  40. "myAL" 
  41. "Count       : {0}" -f $myAL.Count 
  42. "Capacity    : {0}" -f $myAL.Capacity 
  43. "Fixed Len?  : {0}" -f $myAL.IsFixedSize 
  44. "Read only?  : {0}" -f $myAL.IsReadOnly 
  45. "Values   :" 
  46. $myAL 

Thursday, 2 September 2010

Get-UmAlQuraCalendar.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays details of a UmAlQura Calendar in PowerShell 
  4. .DESCRIPTION 
  5.     This script shows the various aspects of this calendar including key properties, 
  6.     fields and selected methods. 
  7. .NOTES 
  8.     File Name  : Get-UmAlQuraCalendar.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com 
  14.     MSDN Sample posted at: 
  15.         http://msdn.microsoft.com/en-us/library/system.globalization.umalquracalendar.aspx 
  16. .EXAMPLE 
  17.     PSH [C:\foo]: .\Get-UmAlQuraCalendar.ps1' 
  18.     Um Al Qura Calendar 
  19.     Algorithm Type          : LunarCalendar 
  20.     Eras in Calendar        : 1 
  21.     Is read only?           : False 
  22.     Max Supported Date/Time : 5/13/2029 11:59:59 PM 
  23.     Min Supported Date/Time : 4/30/1900 12:00:00 AM 
  24.     Two Digit Year Max      : 1451 
  25.   
  26.     April 3, 2002 of the Gregorian calendar equals the following in the UmAlQura calendar: 
  27.        Era:            1 
  28.        Year:           1423 
  29.        Is Leap Year?   False 
  30.        Days In Year:   354 
  31.        Month:          1 
  32.        Months in Year: 12 
  33.        Days in Month:  29 
  34.        Leap Month:     0 
  35.        DayOfYear:      20 
  36.        DayOfMonth:     20 
  37.        DayOfWeek:      Wednesday 
  38.   
  39.     After adding two years and ten months and one day: 
  40.        Era:            1 
  41.        Year:           1425 
  42.        Is Leap Year?   True 
  43.        Days In Year:   355 
  44.        Month:          11 
  45.        Months in Year: 12 
  46.        Days in Month:  30 
  47.        Leap Month:     0 
  48.        DayOfYear:      317 
  49.        DayOfMonth:     21 
  50.        DayOfWeek:      Sunday 
  51. #>     
  52.  
  53. # Helper Function 
  54. Function DisplayValues { 
  55. param ($MyCal, $MyDT
  56.  
  57. "   Era:            {0}" -f $MyCal.GetEra($MyDT)  
  58. "   Year:           {0}" -f $MyCal.GetYear($MyDT
  59. "   Is Leap Year?   {0}" -f $MyCal.IsLeapYear($MyCal.GetYear($MyDT)) 
  60. "   Days In Year:   {0}" -f $MyCal.GetDaysInYear($MyCal.GetYear($MyDT)) 
  61. "   Month:          {0}" -f $MyCal.GetMonth($MyDT
  62. "   Months in Year: {0}" -f $MyCal.GetMonthsInYear($MyCal.GetYear($MyDT)) 
  63. "   Days in Month:  {0}" -f $MyCal.GetDaysInMonth($MyCal.GetYear($MyDT), $MyDT.Month) 
  64. "   Leap Month:     {0}" -f $MyCal.GetLeapMonth($MyCal.GetYear($MyDT)) 
  65. "   DayOfYear:      {0}" -f $MyCal.GetDayOfYear($MyDT
  66. "   DayOfMonth:     {0}" -f $MyCal.GetDayOfMonth($MyDT
  67. "   DayOfWeek:      {0}" -f $MyCal.GetDayOfWeek($MyDT
  68. "" 
  69.        
  70. # Sets a DateTime to April 3, 2002 of the Gregorian calendar. 
  71.  $MyDT = New-Object System.DateTime 2002, 4, 3, (New-Object System.Globalization.GregorianCalendar) 
  72.    
  73. # Creates an instance of the UmAlQuraCalendar. 
  74. $MyCal = New-Object System.Globalization.UmAlQuraCalendar 
  75. # Display properties of the calendar 
  76. "Um Al Qura Calendar" 
  77. "Algorithm Type          : {0}" -f $MyCal.AlgorithmType 
  78. "Eras in Calendar        : {0}" -f $MyCal.Eras.count 
  79. "Is read only?           : {0}" -f $MyCal.IsReadOnly 
  80. "Max Supported Date/Time : {0}" -f $MyCal.MaxSupportedDateTime 
  81. "Min Supported Date/Time : {0}" -f $MyCal.MinSupportedDateTime 
  82. "Two Digit Year Max      : {0}" -f $MyCal.TwoDigitYearMax 
  83. "" 
  84.   
  85. # Display the values of the DateTime. 
  86.  "April 3, 2002 of the Gregorian calendar equals the following in the UmAlQura calendar:"  
  87. DisplayValues $MyCal $MyDT  
  88.  
  89. # Adds two years and ten months and one Day. 
  90. $MyDT = $MyCal.AddYears( $MyDT, 2 ) 
  91. $MyDT = $MyCal.AddMonths($MyDT, 10 ) 
  92. $MyDT = $MyCal.AddDays($MyDT, 1 ) 
  93.   
  94. # Display the values of the DateTime. 
  95. "After adding two years and ten months and one day:" 
  96. DisplayValues $MyCal $MyDT 

Wednesday, 1 September 2010

Get-PersianCalendar.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays details of a Persian calendar in PowerShell 
  4. .DESCRIPTION 
  5.     This script re-implements an MSDN C# sample. 
  6. .NOTES 
  7.     File Name  : Get-PersianCalendar.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://pshscripts.blogspot.com/2010/09/get-persiancalendarps1.html
  13.     MSDN Sample posted at: 
  14.         http://msdn.microsoft.com/en-us/library/system.globalization.persiancalendar.aspx  
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\Get-PersianCalendar.ps1
  17.     ................. Today .......................... 
  18.     Today is: 
  19.        Wednesday, 9/1/2010 03:25:17 PM in the Gregorian calendar. 
  20.        Wednesday, 6/10/1389 15:25:17 in the Persian calendar. 
  21.     ............... Fields ............................ 
  22.     PersianEra = 1 
  23.     ............... Properties ........................ 
  24.     Eras: 
  25.      era = 1 
  26.     Gregorian Date Range Supported by the Persian Calendar: 
  27.        From 3/21/0622 12:00:00 AM 
  28.        To   12/31/9999 11:59:59 PM 
  29.     TwoDigitYearMax = 99 
  30.     ............ Selected Methods ...................... 
  31.     GetDayOfYear: day       = 165 
  32.     GetDaysInMonth: days    = 30 
  33.     GetDaysInYear: days     = 366 
  34.     GetLeapMonth:  month    = 0 
  35.     GetMonthsInYear: months = 12 
  36.     IsLeapDay:              = False 
  37.     IsLeapMonth:            = False 
  38.     IsLeapYear: 1370 is a leap year = True 
  39.     ToFourDigitYear: 
  40.       If TwoDigitYearMax = 99, ToFourDigitYear(99) = 99 
  41.       If TwoDigitYearMax = 2010, ToFourDigitYear(99) = 1999 
  42. #> 
  43. # Get today's date. 
  44. $Jc       = new-object system.Globalization.PersianCalendar 
  45. $ThisDate = [System.DateTime]::Now 
  46.  
  47. # Display the current date using the Gregorian and Persian calendars. 
  48. "Today is:" 
  49. "   {0:dddd}, {0} in the Gregorian calendar." -f $ThisDate 
  50. "   {0}, {1}/{2}/{3} {4}:{5}:{6} in the Persian calendar." -f $jc.GetDayOfWeek($thisDate),  
  51.                         $jc.GetMonth($thisDate),  
  52.                         $jc.GetDayOfMonth($thisDate),  
  53.                         $jc.GetYear($thisDate),  
  54.                         $jc.GetHour($thisDate),  
  55.                         $jc.GetMinute($thisDate),  
  56.                         $jc.GetSecond($thisDate
  57.  
  58. # Fields 
  59. "............... Fields ............................" 
  60. "PersianEra = {0}" -f [System.Globalization.PersianCalendar]::PersianEra 
  61.  
  62. # Properties 
  63. "............... Properties ........................" 
  64. "Eras:" 
  65. foreach ($era in $jc.Eras){ 
  66.          " era = {0}" -f $era 
  67. "Gregorian Date Range Supported by the Persian Calendar:" 
  68. "   From {0:G}" -f $jc.MinSupportedDateTime 
  69. "   To   {0:G}" -f $jc.MaxSupportedDateTime 
  70. "TwoDigitYearMax = {0}" -f $jc.TwoDigitYearMax 
  71.  
  72. # Methods 
  73. "............ Selected Methods ......................" 
  74. "GetDayOfYear: day       = {0}"    -f $jc.GetDayOfYear($thisDate
  75. "GetDaysInMonth: days    = {0}" -f $jc.GetDaysInMonth($thisDate.Year, $thisDate.Month,  
  76.                                    [System.Globalization.PersianCalendar]::PersianEra) 
  77. "GetDaysInYear: days     = {0}" -f $jc.GetDaysInYear($thisDate.Year, [System.Globalization.PersianCalendar]::PersianEra) 
  78. "GetLeapMonth:  month    = {0}" -f $jc.GetLeapMonth($thisDate.Year, [System.Globalization.PersianCalendar]::PersianEra) 
  79. "GetMonthsInYear: months = {0}" -f $jc.GetMonthsInYear($thisDate.Year,[System.Globalization.PersianCalendar]::PersianEra) 
  80. "IsLeapDay:              = {0}" -f $jc.IsLeapDay($thisDate.Year, $thisDate.Month, $thisDate.Day,  
  81.                         [System.Globalization.PersianCalendar]::PersianEra) 
  82. "IsLeapMonth:            = {0}" -f $jc.IsLeapMonth($thisDate.Year, $thisDate.Month,  
  83.                         [System.Globalization.PersianCalendar]::PersianEra) 
  84. "IsLeapYear: 1370 is a leap year = {0}" -f $jc.IsLeapYear(1370, [System.Globalization.PersianCalendar]::PersianEra) 
  85.  
  86. # Get the 4-digit year for a year whose last two digits are 99. The 4-digit year  
  87. # depends on the current value of the TwoDigitYearMax property. 
  88. "ToFourDigitYear:" 
  89. "  If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}" -f $jc.TwoDigitYearMax, $jc.ToFourDigitYear(99) 
  90. $jc.TwoDigitYearMax = $thisDate.Year 
  91. "  If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}" -f $jc.TwoDigitYearMax, $jc.ToFourDigitYear(99)   

Tuesday, 31 August 2010

Get-Cultures.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays information of cultures on a system. 
  4. .DESCRIPTION 
  5.     This script reimplements an MSDN script using PowerShell. It first 
  6.     gets the cultures then displays them 
  7. .NOTES 
  8.     File Name  : Get-Cultures.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINK 
  12.     This script posted to: 
  13.         http://pshscripts.blogspot.com/2010/08/get-cultures.html 
  14.     MSDN sample posted to: 
  15.         http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.getcultures.aspx  
  16. .EXAMPLE 
  17.     PSH [C:\foo]: .\Get-Cultures.ps1' 
  18.     CULTURE ISO ISO WIN DISPLAYNAME                             NATIVENAME 
  19.     af       af  afr AFK Afrikaans                               Afrikaans 
  20.     am       am  amh AMH Amharic                                 Amharic 
  21.     ar       ar  ara ARA Arabic                                  Arabic 
  22.     arn      arn arn MPD Mapudungun                              Mapudungun 
  23.     as       as  asm ASM Assamese                                Assamese 
  24.     az       az  aze AZE Azeri                                   Azeri 
  25.     az-Cyrl  az  aze AZC Azeri (Cyrillic)                        Azeri (Cyrillic) 
  26.     az-Latn  az  aze AZE Azeri (Latin)                           Azeri (Latin) 
  27.     ... snipped to save space! 
  28. #> 
  29.  
  30. # Get Cultures 
  31. $Cultures = [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::NeutralCultures) 
  32.  
  33. # Display header then details 
  34. "CULTURE ISO ISO WIN DISPLAYNAME                             NATIVENAME" 
  35. foreach ($Ci in $Cultures
  36.       { 
  37. "{0,-8} {1,-3} {2,-3} {3,-3} {4,-40}{4,-40}" -f $Ci.Name, 
  38.              $Ci.TwoLetterISOLanguageName, 
  39.              $Ci.ThreeLetterISOLanguageName,   
  40.              $Ci.ThreeLetterWindowsLanguageName, 
  41.              $Ci.DisplayName, 
  42.              $Ci.NativeName 

Sunday, 29 August 2010

Get-Time.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script converts time to different time zones.  
  4. .DESCRIPTION 
  5.     This script re-implements an MSDN sample using PowerShell 
  6. .NOTES 
  7.     File Name  : Get-Time.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://pshscripts.blogspot.com/2010/08/get-time.html 
  13.     MSDN Sample posted at: 
  14.         http://msdn.microsoft.com/en-us/library/system.timezoneinfo.findsystemtimezonebyid.aspx  
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\Get-Time.ps1 
  17.     Time in GMT Daylight Time zone: 8/29/2010 11:40:50 AM 
  18.        UTC Time: 8/29/2010 10:40:50 AM 
  19.     Time in Tokyo Daylight Time zone: 8/29/2010 07:40:50 PM 
  20.        UTC Time: 8/29/2010 10:40:50 AM 
  21. #> 
  22.  
  23. # Get local time 
  24. $thisTime = [system.DateTime]::Now 
  25.  
  26. if ([System.TimeZoneInfo]::Local.IsDaylightSavingTime($thisTime)) { 
  27.     $tzn = [System.TimeZoneInfo]::Local.DaylightName } 
  28. else
  29.     $tzn = [System.TimeZoneInfo]::Local.StandardName 
  30. # Display local Time 
  31. "Time in {0} zone: {1}" -f $tzn, $thisTime 
  32. "   UTC Time: {0}" -f [system.TimeZoneInfo]::ConvertTimeToUtc($thisTime, [TimeZoneInfo]::Local) 
  33.  
  34. # Get Tokyo Standard Time zone 
  35. $tst = [system.TimeZoneInfo]::FindSystemTimeZoneById("Tokyo Standard Time"
  36. $tstTime = [system.TimeZoneInfo]::ConvertTime($thisTime, [TimeZoneInfo]::local, $tst
  37. $tstzn = if ( [System.TimeZoneInfo]::Local.IsDaylightSavingTime($tstTime)) { 
  38.          $tst.DaylightName} else {$tst.StandardName} 
  39.  
  40. # Display Tokyo Time Zone 
  41. "Time in {0} zone: {1}" -f $tstzn,$tstTime 
  42. "   UTC Time: {0}" -f [System.TimeZoneInfo]::ConvertTimeToUtc($tstTime, $tst

Saturday, 28 August 2010

Get-TimeZoneInfoInfo

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays/Uses TimeZoneInfo properties  
  4. .DESCRIPTION 
  5.     This script displays the use of all the TimeZoneInfo Properties. 
  6. .NOTES 
  7.     File Name  : Get-TimeZoneInfoInfo.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://pshscripts.blogspot.com/2010/08/get-timezoneinfoinfo.html 
  13.     MSDN Sample posted at: 
  14.         http://msdn.microsoft.com/en-us/library/system.timezoneinfo_properties.aspx    
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .Get-TimeZoneInfoInfo.ps1' 
  17.     Time Zone: (GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London 
  18.       Time zone is 0 hours 0 minutes later than Coordinated Universal Time. 
  19.       Current time is 12:22 PM on 8/28/2010 GMT Daylight Time 
  20.       Timezone id              : GMT Standard Time 
  21.       Supports Daylight Saving : True 
  22.       Daylight Saving Zone Name: GMT Daylight Time 
  23.   
  24.     Time Zone: (GMT+04:30) Kabul 
  25.       Time zone is 4 hours 30 minutes later than Coordinated Universal Time. 
  26.       Current time is 12:22 PM on 8/28/2010 Afghanistan Standard Time 
  27.       Timezone id              : Afghanistan Standard Time 
  28.       Supports Daylight Saving : False 
  29.       Daylight Saving Zone Name: Afghanistan Daylight Time 
  30.   
  31.     Time Zone: UTC 
  32.       Time zone is 0 hours 0 minutes later than Coordinated Universal Time. 
  33.       Current time is 12:22 PM on 8/28/2010 UTC 
  34.       Timezone id              : UTC 
  35.       Supports Daylight Saving : False 
  36.       Daylight Saving Zone Name: UTC 
  37. #> 
  38. # Display Information About Time Zones 
  39.  
  40. # Get current date 
  41. $Datenow = Get-Date 
  42.  
  43. # Display info re Local Time Zone 
  44. $LocalZone = [System.TimeZoneInfo]::Local 
  45. $t1 = [system.Math]::Abs($LocalZone.BaseUtcOffset.Hours) 
  46. $t2 = [System.Math]::Abs($LocalZone.BaseUtcOffset.Minutes)  
  47. $t3 = if ($LocalZone.BaseUtcOffset -ge  [System.Timespan]::Zero) {"later"} else {"earlier"
  48. $t4 = if ($LocalZone.IsdaylightSavingTime($datenow)) {$Localzone.DaylightName} else {$Localzone.Standardname} 
  49. "Time Zone: {0}" -f $Localzone.Displayname 
  50. "  Time zone is {0} hours {1} minutes {2} than Coordinated Universal Time." -f   $t1,$t2, $t3 
  51. "  Current time is {0:t} on {0:d} {1}" -f $datenow,$t4 
  52. "  Timezone id              : {0}" -f $LocalZone.Id 
  53. "  Supports Daylight Saving : {0}" -f $LocalZone.SupportsDaylightSavingTime 
  54. "  Daylight Saving Zone Name: {0}" -f $Localzone.DaylightName 
  55. "" 
  56.  
  57. # Get Kabul Time 
  58. $Kt = [system.TimeZoneInfo]::GetSystemTimeZones()  | ? {$_.id -match "Afghanistan Standard Time"
  59. $tz = $kt.Displayname 
  60. $t1 = [system.Math]::Abs($kt.BaseUtcOffset.Hours) 
  61. $t2 = [System.Math]::Abs($kt.BaseUtcOffset.Minutes)  
  62. $t3 = if ($kt.BaseUtcOffset -ge  [System.timespan]::Zero) {"later"} else {"earlier"
  63. $t4 = if ($Kt.IsdaylightSavingTime($datenow)) {$Kt.DaylightName} else {$Kt.Standardname} 
  64.  
  65. # Display information 
  66. "Time Zone: {0}" -f $Kt.Displayname 
  67. "  Time zone is {0} hours {1} minutes {2} than Coordinated Universal Time." -f   $t1,$t2,$t3 
  68. "  Current time is {0:t} on {0:d} {1}" -f $datenow,$t4 
  69. "  Timezone id              : {0}" -f $Kt.Id 
  70. "  Supports Daylight Saving : {0}" -f $Kt.SupportsDaylightSavingTime 
  71. "  Daylight Saving Zone Name: {0}" -f $Kt.DaylightName 
  72. "" 
  73.  
  74. # Display Information regarding UTC 
  75. $UtcZone = [System.TimeZoneInfo]::UTC 
  76. $t1 = [system.Math]::Abs($UtcZone.BaseUtcOffset.Hours) 
  77. $t2 = [System.Math]::Abs($UtcZone.BaseUtcOffset.Minutes)  
  78. $t3 = if ($UtcZone.BaseUtcOffset -ge  [System.Timespan]::Zero) {"later"} else {"earlier"
  79. $t4 = if ($UtcZone.IsdaylightSavingTime($datenow)) {$Utczone.DaylightName} else {$UtcZone.Standardname} 
  80.  
  81. # Display information 
  82. "Time Zone: {0}" -f $UtcZone.Displayname 
  83. "  Time zone is {0} hours {1} minutes {2} than Coordinated Universal Time." -f   $t1,$t2,$t3 
  84. "  Current time is {0:t} on {0:d} {1}" -f $Datenow,$t4 
  85. "  Timezone id              : {0}" -f $UtcZone.Id 
  86. "  Supports Daylight Saving : {0}" -f $UtcZone.SupportsDaylightSavingTime 
  87. "  Daylight Saving Zone Name: {0}" -f $UtcZone.DaylightName 

Wednesday, 25 August 2010

Get-NoDstTimeZones

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays those time zones that do NOT support 
  4.     daylight savings time. 
  5. .DESCRIPTION 
  6.     This script uses .NET to get the time zones defined on a system 
  7.     then displays those that do not suport daylight savings time. 
  8. .NOTES 
  9.     File Name  : Get-NoDstTimeZones.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15.     MSDN Sample posted at: 
  16.        http://msdn.microsoft.com/en-us/library/system.timezoneinfo.supportsdaylightsavingtime.aspx 
  17. .EXAMPLE 
  18.     PSH [C:\foo]: .\Get-NoDstTimeZones.ps1' 
  19.     (UTC) Coordinated Universal Time 
  20.     (UTC) Monrovia, Reykjavik 
  21.     (UTC+01:00) West Central Africa 
  22.     ... {output snipped to save space} 
  23. #> 
  24.  
  25. # Get Time Zones 
  26. $zones = [System.TimeZoneInfo]::GetSystemTimeZones() 
  27.  
  28. # For each zone, display name if the zone does not support dst 
  29. foreach($zone in $zones) { 
  30.    if (! $zone.SupportsDaylightSavingTime) {$zone.DisplayName} 

Tuesday, 17 August 2010

Get-BrokenHardware.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets a list of non-working hardware using WMI. 
  4. .DESCRIPTION 
  5.     This script re-implements another TechNet Scripting 
  6.     Gallery script that was written in VB (see  
  7.     http://tinyurl.com/y4hmtbr).  
  8.     This script first uses WMI to get system details, then 
  9.     gets and displays hardware that has errored. 
  10. .NOTES 
  11.     File Name  : Get-BrokenHardware.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 2.0 
  14. .LINK 
  15.     This script posted to: 
  16.         http://www.pshscripts.blogspot.com 
  17.     This script posted to TechNet Script Gallery at: 
  18.         http://gallery.technet.microsoft.com/ScriptCenter/en-us/dbb678f4-b95b-45c3-bc8b-2ae2d052448e     
  19. .EXAMPLE 
  20.     PSH [C:\foo]: Get-BrokenHardware.ps1 
  21.     Computer Details: 
  22.     Manufacturer: Dell Inc. 
  23.     Model:        Precision WorkStation T7400 
  24.     Service Tag:  6Y84C3J 
  25.  
  26.     Hardware that's not working list 
  27.     Description:  WD My Book Device USB Device 
  28.     Device ID:    USBSTOR\OTHER&VEN_WD&PROD_MY_BOOK_DEVICE&REV_1010\7&2A4E07C&0&575532513130303732383932&1 
  29.     Error ID:     28 
  30. #> 
  31.  
  32. # Display Computer details 
  33. "Computer Details:" 
  34. $comp = gwmi Win32_ComputerSystem 
  35. "Manufacturer: {0}" -f $comp.Manufacturer 
  36. "Model:        {0}" -f $comp.Model 
  37. $computer2 = Get-WmiObject Win32_ComputerSystemProduct 
  38. "Service Tag:  {0}" -f $computer2.IdentifyingNumber 
  39. "" 
  40.  
  41. #Get hardware that is errored 
  42. "Hardware that's not working list"  
  43. $broken = Get-WmiObject Win32_PnPEntity | where {$_.ConfigManagerErrorCode -ne 0} 
  44.  
  45. #Display broken hardware 
  46. foreach ($obj in $broken){   
  47. "Description:  {0}" -f  $obj.Description 
  48. "Device ID:    {0}" -f  $obj.DeviceID 
  49. "Error ID:     {0}" -f  $obj.ConfigManagerErrorCode 
  50. ""