Tuesday, 8 November 2011

Show-TimeSpan.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script, a re-implementation of an MSDN sample, shows 
  4.     details of a timespan object 
  5. .DESCRIPTION 
  6.     This script re-implements a simple MSDN script that creates a  
  7.     timespan object and displays its properties. 
  8. .NOTES 
  9.     File Name  : Show-TimeSpan.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 to: 
  16.         http://msdn.microsoft.com/en-us/library/system.timespan.aspx 
  17. .EXAMPLE 
  18.      Psh> .\Show-TimeSpan.ps1 
  19.     8/18/2010 1:30:30 PM - 1/1/2010 8:00:15 AM = 229.05:30:15 
  20.        Value of Days Component:                             229 
  21.        Total Number of Days:                   229.229340277778 
  22.        Value of Hours Component:                              5 
  23.        Total Number of Hours:                  5501.50416666667 
  24.        Value of Minutes Component:                           30 
  25.        Total Number of Minutes:                       330090.25 
  26.        Value of Seconds Component:                           15 
  27.        Total Number of Seconds:                      19,805,415 
  28.        Value of Milliseconds Component:                       0 
  29.        Total Number of Milliseconds:             19,805,415,000 
  30.        Ticks:                               198,054,150,000,000 
  31. #> 
  32.  
  33. # Define two dates 
  34. $date1 = new-object system.datetime 2010, 1, 1, 8, 0, 15 
  35. $date2 = new-object system.datetime 2010, 8, 18, 13, 30, 30 
  36.  
  37. # Create a time Interval 
  38. $interval = New-Timespan -start $date1 -end $date2 
  39.  
  40. #Display the interval 
  41. "{0} - {1} = {2}" -f $date2, $date1, $interval.ToString() 
  42.  
  43. # Display individual properties of the resulting TimeSpan object. 
  44. "   {0,-35} {1,20}" -f "Value of Days Component:", $interval.Days 
  45. "   {0,-35} {1,20}" -f "Total Number of Days:", $interval.TotalDays 
  46. "   {0,-35} {1,20}" -f "Value of Hours Component:", $interval.Hours 
  47. "   {0,-35} {1,20}" -f "Total Number of Hours:", $interval.TotalHours 
  48. "   {0,-35} {1,20}" -f "Value of Minutes Component:", $interval.Minutes 
  49. "   {0,-35} {1,20}" -f "Total Number of Minutes:", $interval.TotalMinutes 
  50. "   {0,-35} {1,20:N0}" -f "Value of Seconds Component:", $interval.Seconds 
  51. "   {0,-35} {1,20:N0}" -f "Total Number of Seconds:", $interval.TotalSeconds 
  52. "   {0,-35} {1,20:N0}" -f "Value of Milliseconds Component:", $interval.Milliseconds 
  53. "   {0,-35} {1,20:N0}" -f "Total Number of Milliseconds:", $interval.TotalMilliseconds 
  54. "   {0,-35} {1,20:N0}" -f "Ticks:", $interval.Ticks 

Show-UnicodeCharacters.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script, a re-implementation of an MSDN sample, shows the  
  4.     Unicode details of a unicode character, using PowerShell. 
  5. .DESCRIPTION 
  6.     This script re-implements a simple MSDN script that takes a Unicode Character 
  7.     and uses CharUnicodeInfo class to get details of that character, which are then 
  8.     displayed. 
  9. .NOTES 
  10.     File Name  : Show-UnicodeCharacters.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://pshscripts.blogspot.com/2011/11/show-unicodecharactersps1.html 
  16.     MSDN sample posted to: 
  17.         http://msdn.microsoft.com/en-us/library/system.globalization.charunicodeinfo.aspx
  18. .EXAMPLE 
  19.      Psh > .\show-unicodecharacters.ps1 
  20.                                             c    Num    Dig   Dec    UnicodeCategory 
  21.     U+0061 LATIN SMALL LETTER A             a    -1      -1    -1    LowercaseLetter 
  22.     U+0393 GREEK CAPITAL LETTER GAMMA       Γ    -1      -1    -1    UppercaseLetter 
  23.     U+0039 DIGIT NINE                       9    9       9     9     DecimalDigitNumber 
  24.     U+00B2 SUPERSCRIPT TWO                  ²    2       2     -1    OtherNumber 
  25.     U+00BC VULGAR FRACTION ONE QUARTER      ¼    0.25    -1    -1    OtherNumber 
  26.     U+0BEF TAMIL DIGIT NINE                 ௯    9      9     9     DecimalDigitNumber 
  27.     U+0BF0 TAMIL NUMBER TEN                 ௰    10     -1    -1     OtherNumber 
  28.     U+0F33 TIBETAN DIGIT HALF ZERO          ༳    -0.5    -1    -1     OtherNumber 
  29.     U+2788 CIRCLED SANS-SERIF DIGIT NINE    ➈    9       9    -1     OtherNumber 
  30. #> 
  31.  
  32. # Helper Function 
  33. Function PrintProperties { 
  34.   param ($char) 
  35.   $fmtstring = " {0,-5}  {1,-8}  {2,-9}  {3,-9}  {4,-9}" 
  36.   $a = $char 
  37.   $b = [System.Globalization.CharUnicodeInfo]::GetNumericValue( $char ) 
  38.   $c = [System.Globalization.CharUnicodeInfo]::GetDigitValue( $char )  
  39.   $d = [System.Globalization.CharUnicodeInfo]::GetDecimalDigitValue( $char ) 
  40.   $e = [System.Globalization.CharUnicodeInfo]::GetUnicodeCategory( $char ) 
  41.   $fmtstring -f $a, $b, $c, $d, $e 
  42. }  
  43. "                                        c      Num      Dig        Dec         UnicodeCategory"  
  44. "U+0061 LATIN SMALL LETTER A            "  + (PrintProperties  "a") 
  45. "U+0393 GREEK CAPITAL LETTER GAMMA      "  + (PrintProperties  ([Char] 0x0393) ) 
  46. "U+0039 DIGIT NINE                      "  + (PrintProperties  "9") 
  47.  
  48. "U+00B2 SUPERSCRIPT TWO                 "  + (PrintProperties  $([Char] 0x00B2) ) 
  49.  
  50. "U+00BC VULGAR FRACTION ONE QUARTER     "  + (PrintProperties  $([Char] 0x00BC) ) 
  51. "U+0BEF TAMIL DIGIT NINE                "  + (PrintProperties  $([Char] 0x0BEF) ) 
  52. "U+0BF0 TAMIL NUMBER TEN                "  + (PrintProperties  $([Char] 0x0BF0) ) 
  53. "U+0F33 TIBETAN DIGIT HALF ZERO         "  + (PrintProperties  $([Char] 0x0F33) ) 
  54. "U+2788 CIRCLED SANS-SERIF DIGIT NINE   "  + (PrintProperties  $([Char] 0x2788) ) 

Tuesday, 1 November 2011

Show-DateTimeFormatInfo.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script re-implements and MSDN sample that shows 
  4.     the different Date/Time Formatting characters and 
  5.     how they are used in formatting date/time objects. 
  6. .DESCRIPTION 
  7.     This script Creates a date/time object, then shows formatting 
  8.     using the key Date/Time Format strings. 
  9. .NOTES 
  10.     File Name  : Show-DateTimeFormatInfo.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN sample posted to: 
  17.         http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx 
  18. .EXAMPLE 
  19.     Left as an exercise for the reader. 
  20.      
  21. #> 
  22.  
  23.  
  24. # Create and initialise a DateTimeFormatInfo associated with the en-US culture. 
  25.  $MyDTFI = (new-object System.Globalization.CultureInfo "en-US", $false ).DateTimeFormat 
  26.  
  27. # Create a DateTime with the Gregorian date January 3, 2002 (year=2002, month=1, day=3) 
  28. # The Gregorian calendar is the default calendar for the en-US culture 
  29. $MyDT = new-object System.DateTime  2002, 1, 3  
  30.  
  31. # Display the format pattern associated with each format character 
  32. "FORMAT  en-US EXAMPLE" 
  33. "CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY"  
  34. "  d     {0}"          -f $MyDT.ToString("d", $MyDTFI)  
  35. "        {0}    {1}`n" -f $MyDTFI.ShortDatePattern, "(ShortDatePattern)" 
  36. "  D     {0}"          -f $MyDT.ToString("D", $MyDTFI) 
  37. "        {0}    {1}`n" -f $MyDTFI.LongDatePattern, "(LongDatePattern)" 
  38. "  f     {0}`n"        -f $MyDT.ToString("f", $MyDTFI) 
  39. "  F     {0}"          -f $MyDT.ToString("F", $MyDTFI) 
  40. "        {0}    {1}`n" -f $MyDTFI.FullDateTimePattern, "(FullDateTimePattern)" 
  41. "  g     {0}`n"        -f $MyDT.ToString("g", $MyDTFI) 
  42. "  G     {0}`n"        -f $MyDT.ToString("G", $MyDTFI) 
  43. "  m     {0}"          -f $MyDT.ToString("m", $MyDTFI) 
  44. "        {0}    {1}`n" -f $MyDTFI.MonthDayPattern, "(MonthDayPattern)" 
  45. "  M     {0}"          -f $MyDT.ToString("M", $MyDTFI)  
  46. "        {0}    {1}`n" -f $MyDTFI.MonthDayPattern, "(MonthDayPattern)" 
  47. "  o     {0}`n"        -f $MyDT.ToString("o", $MyDTFI) 
  48. "  r     {0}"          -f $MyDT.ToString("r", $MyDTFI)  
  49. "        {0}    {1}`n" -f $MyDTFI.RFC1123Pattern, "(RFC1123Pattern)" 
  50. "  R     {0}"          -f $MyDT.ToString("R", $MyDTFI)  
  51. "        {0}    {1}`n" -f $MyDTFI.RFC1123Pattern, "(RFC1123Pattern)" 
  52. "  s     {0}"          -f $MyDT.ToString("s", $MyDTFI)  
  53. "        {0}    {1}`n" -f $MyDTFI.SortableDateTimePattern, "(SortableDateTimePattern)" 
  54. "  t     {0}"          -f $MyDT.ToString("t", $MyDTFI)  
  55. "        {0}    {1}`n" -f $MyDTFI.ShortTimePattern, "(ShortTimePattern)" 
  56. "  T     {0}"          -f $MyDT.ToString("T", $MyDTFI)  
  57. "        {0}    {1}`n" -f $MyDTFI.LongTimePattern, "(LongTimePattern)" 
  58. "  u     {0}"          -f $MyDT.ToString("u", $MyDTFI)  
  59. "        {0}    {1}`n" -f $MyDTFI.UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)" 
  60. "  U     {0}`n"        -f $MyDT.ToString("U", $MyDTFI) 
  61. "  y     {0}"          -f $MyDT.ToString("y", $MyDTFI)  
  62. "        {0}    {1}`n" -f $MyDTFI.YearMonthPattern, "(YearMonthPattern)" 
  63. "  Y     {0}"          -f $MyDT.ToString("Y", $MyDTFI)  
  64. "        {0}    {1}`n" -f $MyDTFI.YearMonthPattern, "(YearMonthPattern)" 

Show-CurrencyDecimalSeparator.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script re-implements an MSDN script which 
  4.     shows the use of the CurrencyDecimalSeparator 
  5.     property of a numeric format info object.  
  6. .DESCRIPTION 
  7.     This script displays a currency value using  
  8.     the default decimal separator then shows using a 
  9.     custom separator. This is repeated using a German 
  10.     culture.    
  11. .NOTES 
  12.     File Name  : Show-CurrencyDecimalSeparator.ps1 
  13.     Author     : Thomas Lee - tfl@psp.co.uk 
  14.     Requires   : PowerShell Version 2.0 
  15. .LINK 
  16.     This script posted to: 
  17.         http://www.pshscripts.blogspot.com 
  18.     MSDN sample posted to: 
  19.         http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencydecimalseparator.aspx 
  20. .EXAMPLE 
  21.      Psh> .\Show-CurrencyDecimalSeparator.ps1 
  22.     $123,456,789.00 
  23.     $123,456,789 00 
  24.     123.456.789,00 € 
  25.     123.456.789 00 € 
  26. #> 
  27.  
  28. #    Get a NumberFormatInfo associated with the en-US culture 
  29. $nfi = (new-object System.Globalization.CultureInfo "en-US", $false ).NumberFormat 
  30.  
  31. #    Display a value with the default separator ("."). 
  32. $myInt = 123456789 
  33. $myInt.ToString( "C", $nfi )  
  34.  
  35. #    Display the same value with a blank as the separator. 
  36. $nfi.CurrencyDecimalSeparator = " " 
  37. $myInt.ToString( "C", $nfi )  
  38.  
  39. #    Now get a NumberFormatInfo associated with the de-DE culture 
  40. $nfi = (new-object System.Globalization.CultureInfo "de-DE", $false ).NumberFormat 
  41.  
  42. #    Display a value with the default separator (".") 
  43. $myInt = 123456789 
  44. $myInt.ToString( "C", $nfi )  
  45.  
  46. #    Display the same value with a blank as the separator 
  47. $nfi.CurrencyDecimalSeparator = " " 
  48. $myInt.ToString( "C", $nfi )  

Monday, 31 October 2011

Show-CurrencyFormatting.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script re-implements an MSDN Sample showing the  
  4.     use of the NumberFormatInfo class to nicely format things 
  5.     in this case, currency. 
  6. .DESCRIPTION 
  7.     This script iterates through the Windows cultures and 
  8.     displays those whose 2-letter ISO code is 'en' and  
  9.     displays how Windows formats currency in that culture.  
  10. .NOTES 
  11.     File Name  : Show-CurrencyFormatting.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.     MSDN sample posted to: 
  18.         http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.aspx 
  19. .EXAMPLE 
  20.     Psh > .\Show-CurrencyFormatting.ps1 
  21.     The currency symbol for 'English (United States)' is '$' 
  22.     The currency symbol for 'English (United Kingdom)' is '£' 
  23.     The currency symbol for 'English (Australia)' is '$' 
  24.     The currency symbol for 'English (Canada)' is '$' 
  25.     The currency symbol for 'English (New Zealand)' is '$' 
  26.     The currency symbol for 'English (Ireland)' is '€' 
  27.     The currency symbol for 'English (South Africa)' is 'R' 
  28.     The currency symbol for 'English (Jamaica)' is 'J$' 
  29.     The currency symbol for 'English (Caribbean)' is '$' 
  30.     The currency symbol for 'English (Belize)' is 'BZ$' 
  31.     The currency symbol for 'English (Trinidad and Tobago)' is 'TT$' 
  32.     The currency symbol for 'English (Zimbabwe)' is 'Z$' 
  33.     The currency symbol for 'English (Republic of the Philippines)' is 'Php' 
  34.     The currency symbol for 'English (Singapore)' is '$' 
  35.     The currency symbol for 'English (Malaysia)' is 'RM' 
  36.     The currency symbol for 'English (India)' is 'Rs.' 
  37.  
  38. #> 
  39.  
  40. #   Loop through all the specific cultures known to the CLR. 
  41. foreach ($ci in [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::SpecificCultures))  
  42.         { 
  43.             # Only show the currency symbols for cultures that speak English. 
  44.             if ($ci.TwoLetterISOLanguageName -eq "en") { 
  45.             # Display the culture name and currency symbol. 
  46.                $nfi = $ci.NumberFormat 
  47.                "The currency symbol for '{0}' is '{1}'" -f $ci.DisplayName, $nfi.CurrencySymbol 
  48.             } 
  49.         } 

Show-CalendarAlgorithm.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script re-implements an MSDN Sample showing the  
  4.     CalendarAlgorithmType enumeration.  
  5. .DESCRIPTION 
  6.     This script creates there calendars and displays  
  7.     algorithm type, 
  8. .NOTES 
  9.     File Name  : Show-CalendarAlgorithm.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 to: 
  16.         http://msdn.microsoft.com/en-us/library/system.globalization.calendaralgorithmtype.aspx 
  17. .EXAMPLE 
  18.      
  19. #> 
  20.  
  21. # Helper function 
  22. Function Display{ 
  23. Param ([System.Globalization.Calendar] $c) 
  24. $name = $c.ToString().PadRight(50, '.') 
  25. "{0} {1}" -f $name, $c.AlgorithmType 
  26. } 
  27.  
  28. ## Start of script 
  29.  
  30. # Create three new calendars 
  31. $grCal = new-object System.Globalization.GregorianCalendar 
  32. $hiCal = new-object System.Globalization.HijriCalendar 
  33. $jaCal = new-object System.Globalization.JapaneseLunisolarCalendar 
  34.  
  35. # Display them 
  36. Display($grCal); 
  37. Display($hiCal); 
  38. Display($jaCal); 
  39.  
  40. [enum]::GetNames([System.Globalization.CalendarAlgorithmType]) 

Show-CurrencyGroupSize

  1. <# 
  2. .SYNOPSIS 
  3.     This script reimplements a code sample from MSDN in PowerShell. 
  4.     This sample formats and display currency using standard and 
  5.     different currency groupings.  
  6. .DESCRIPTION 
  7.     This script displays a currency using standard, then two 
  8.     custom CurrencyGroupSizes. 
  9. .NOTES 
  10.     File Name  : Show-CurrencyGroupSize.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN sample posted tot: 
  17.         http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencygroupsizes.aspx  
  18. .EXAMPLE 
  19.     PSH:> .\Show-CurrencyGroupSize.ps1 
  20.     Default numeric format string "C" 
  21.     $123,456,789,012,345.00 
  22.  
  23.     Display with array = 2,3,4 
  24.     $12,3456,7890,123,45.00 
  25.  
  26.     Display with array = 2,3,0 
  27.     $1234567890,123,45.00 
  28. #> 
  29.  
  30. #     Get a NumberFormatInfo associated with the en-US culture. 
  31. $fi = new-object System.Globalization.CultureInfo "en-US", false 
  32. $nfi = $fi.NumberFormat 
  33.  
  34. #     Display a value with the default separator (".") 
  35. "Default numeric format string `"C`"" 
  36. [Int64] $myInt = 123456789012345 
  37. $myInt.ToString( "C", $nfi ) 
  38.  
  39. #    Display the same value with different groupings. 
  40. [int[]] $mySizes1 = (2,3,4) 
  41. $mySizes = 2,3,0 
  42.  
  43. "";"Display with array = 2,3,4" 
  44. $nfi.CurrencyGroupSizes = $mySizes1 
  45. $myInt.ToString( "C", $nfi ) 
  46.  
  47. "";"Display with array = 2,3,0" 
  48. $nfi.CurrencyGroupSizes = $mySizes2 
  49. $myInt.ToString( "C", $nfi ) 

Show-StandardNFS-1.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script shows the first two samples on this MSDN Page, 
  4.     convered to PowerShell  
  5. .DESCRIPTION 
  6.     This script displays two lines of text using PowerShell 
  7.     and .NET formatting information 
  8. .NOTES 
  9.     File Name  : Show-StandardNFS-1.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 tot: 
  16.         http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx 
  17. .EXAMPLE 
  18.     [Cookham8:C:\foo]> .\Show-StandardNFS.ps1 
  19.     $123.46 
  20.     Your account balance is $123.46. 
  21. #> 
  22.  
  23. # Show formatting a number as currency 
  24. $value = 123.456 
  25. $value.ToString("C2") 
  26.  
  27. # Show the -f operator with currency formatting 
  28. $value = 123.456 
  29. "Your account balance is {0:C2}." -f $value 

Tuesday, 11 October 2011

Get-OSInstallDate.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets/displays the Sysgtem Uptime after 
  4.     converting it from WEBM time/date format  
  5. .DESCRIPTION 
  6.     This script creates an instance of a SWbemDateTime object,  
  7.     gets the OS install date and converts the date to a more 
  8.     useful format. 
  9. .NOTES 
  10.     File Name  : Get-OSInstallDate.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN sample posted to: 
  17.         http://msdn.microsoft.com/en-us/library/aa393687%28VS.85%29.aspx 
  18. .EXAMPLE 
  19.     Psh [C:\foo]> .\Get-OsInstallDate.ps1 
  20.     This OS was installed in the year 2008 
  21.     Full installation date (VT_DATE format) is 4/9/2008 8:17:23 PM 
  22.     Full installation date (FILETIME format) is 128522458430000000 
  23.  
  24. #> 
  25.  
  26. # Create swbemdatetime object 
  27. $datetime = New-Object -ComObject WbemScripting.SWbemDateTime 
  28.  
  29. #  Get OS installation time and assign to datetime object 
  30. $os = Get-WmiObject -Class Win32_OperatingSystem 
  31. $dateTime.Value = $os.InstallDate 
  32.  
  33. # Now display the time 
  34. "This OS was installed in the year {0}"           -f $dateTime.Year 
  35. "Full installation date (VT_DATE format) is {0}"  -f $dateTime.GetVarDate() 
  36. "Full installation date (FILETIME format) is {0}" -f $dateTime.GetFileTime()  
  37. ## 

Friday, 7 October 2011

Register-Event1.ps1


  1. <# 
  2. .SYNOPSIS 
  3.     This script registers for a WMI event 
  4. .DESCRIPTION 
  5.     This script used PowerShell to register for then display 
  6.     an event. This script is a re-write on an MSDN Sample. 
  7. .NOTES 
  8.     File Name  : Register-Event1.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/aa393013%28VS.85%29.aspx 
  16. .EXAMPLE 
  17.     [PSH] C:\FOO> Register-Event1.ps1 
  18.     Waiting for events 
  19.     Log Event Occured 
  20.     EVENT MESSAGE 
  21.     A logon was attempted using explicit credentials. 
  22.  
  23.     Subject: 
  24.     Security ID:        S-1-5-21-2824006062-479960714-4144511058-1105 
  25.     Account Name:       tfl 
  26.     ...  -> Reminder snipped for brevity 
  27.     
  28. #> 
  29.  
  30. # Define event Query 
  31. $query = "SELECT * FROM __InstanceCreationEvent  
  32.           WHERE TargetInstance ISA 'Win32_NTLogEvent' " 
  33.  
  34. # Register for event - also specify an action that 
  35. # displays the log event when the event fires. 
  36. Register-WmiEvent -Source Demo1 -Query $query -Action { 
  37.                 Write-Host "Log Event occured" 
  38.                 $global:myevent = $event 
  39.                 Write-Host "EVENT MESSAGE" 
  40.                 Write-Host $event.SourceEventArgs.NewEvent.TargetInstance.Message} 
  41. # So wait 
  42. "Waiting for events" 
Technorati Tags: ,,,