Showing posts with label Power. Show all posts
Showing posts with label Power. Show all posts

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 

Monday, 14 February 2011

New-Shortcut.ps1

  1. <# 
  2. .SYNOPSIS 
  3.    This script creates a shortcut to Notepad on the Desktop 
  4. .DESCRIPTION 
  5.    This script creates a Wscript.shell item, then creates  
  6.    a shortcut on the desktop to Notepad.exe. 
  7. .NOTES 
  8.     File Name  : New-Shortcut.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINKS 
  12.     This post is a re-implementation of an MSDN Script 
  13.         http://msdn.microsoft.com/en-us/library/0ea7b5xe%28VS.85%29.aspx 
  14.     Posted to Powershell Scripts Blog 
  15.         HTTP://Pshscripts.blogspot.com 
  16. .EXAMPLE 
  17.    Left as an exercise for the reader 
  18. #> 
  19.  
  20. # create wscript object 
  21. $WshShell = New-Object -com Wscript.Shell 
  22.  
  23. #Get Desktop location 
  24. $Desktop  = $WshShell.SpecialFolders.item("Desktop") 
  25.  
  26. # create a new shortcut 
  27. $ShellLink                  = $WshShell.CreateShortcut($Desktop + "\Shortcut Script.lnk") 
  28. $ShellLink.TargetPath       = $WScript.ScriptFullName 
  29. $ShellLink.WindowStyle      = 1 
  30. $ShellLink.Hotkey           = "CTRL+SHIFT+F" 
  31. $ShellLink.IconLocation     = "notepad.exe, 0" 
  32. $ShellLink.Description      = "Shortcut Script" 
  33. $ShellLink.WorkingDirectory = $Desktop 
  34.  
  35. #Save the link to the desktop 
  36. $ShellLink.Save() 

Tuesday, 29 June 2010

Remove-XMLAttribute.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script removes an an attribute from an XML element. 
  4. .DESCRIPTION 
  5.     This script creates an XML document, then removes an 
  6.     Attribute using the RemoveAttribute method. 
  7. .NOTES 
  8.     File Name  : Remove-XMLAttribute.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/z267hx58.aspx 
  16. .EXAMPLE 
  17.     PSH [C:\foo]: .\Remove-XMLAttribute.ps1
  18.     Display the initial XML... 
  19.     <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> 
  20.     Display the modified XML... 
  21.     <book ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> 
  22. #> 
  23.  
  24. # Create and load an XML Document 
  25. $Doc = New-Object System.Xml.XmlDocument 
  26. $Doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + 
  27.                 "<title>Pride And Prejudice</title>" + 
  28.                 "</book>") 
  29. # Set root 
  30. $Root = $Doc.DocumentElement 
  31.  
  32. # Display initial XML 
  33. "Display the initial XML..." 
  34. $Doc.InnerXml 
  35.  
  36. # Remove the genre attribute 
  37. $Return = $Root.RemoveAttribute("genre") 
  38.  
  39. # Display result 
  40. "Display the modified XML..." 
  41. $Doc.InnerXml