- <#
- .SYNOPSIS
- This script, a re-implementation of an MSDN sample, shows
- details of a timespan object
- .DESCRIPTION
- This script re-implements a simple MSDN script that creates a
- timespan object and displays its properties.
- .NOTES
- File Name : Show-TimeSpan.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.timespan.aspx
- .EXAMPLE
- Psh> .\Show-TimeSpan.ps1
- 8/18/2010 1:30:30 PM - 1/1/2010 8:00:15 AM = 229.05:30:15
- Value of Days Component: 229
- Total Number of Days: 229.229340277778
- Value of Hours Component: 5
- Total Number of Hours: 5501.50416666667
- Value of Minutes Component: 30
- Total Number of Minutes: 330090.25
- Value of Seconds Component: 15
- Total Number of Seconds: 19,805,415
- Value of Milliseconds Component: 0
- Total Number of Milliseconds: 19,805,415,000
- Ticks: 198,054,150,000,000
- #>
- # Define two dates
- $date1 = new-object system.datetime 2010, 1, 1, 8, 0, 15
- $date2 = new-object system.datetime 2010, 8, 18, 13, 30, 30
- # Create a time Interval
- $interval = New-Timespan -start $date1 -end $date2
- #Display the interval
- "{0} - {1} = {2}" -f $date2, $date1, $interval.ToString()
- # Display individual properties of the resulting TimeSpan object.
- " {0,-35} {1,20}" -f "Value of Days Component:", $interval.Days
- " {0,-35} {1,20}" -f "Total Number of Days:", $interval.TotalDays
- " {0,-35} {1,20}" -f "Value of Hours Component:", $interval.Hours
- " {0,-35} {1,20}" -f "Total Number of Hours:", $interval.TotalHours
- " {0,-35} {1,20}" -f "Value of Minutes Component:", $interval.Minutes
- " {0,-35} {1,20}" -f "Total Number of Minutes:", $interval.TotalMinutes
- " {0,-35} {1,20:N0}" -f "Value of Seconds Component:", $interval.Seconds
- " {0,-35} {1,20:N0}" -f "Total Number of Seconds:", $interval.TotalSeconds
- " {0,-35} {1,20:N0}" -f "Value of Milliseconds Component:", $interval.Milliseconds
- " {0,-35} {1,20:N0}" -f "Total Number of Milliseconds:", $interval.TotalMilliseconds
- " {0,-35} {1,20:N0}" -f "Ticks:", $interval.Ticks
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Showing posts with label Power. Show all posts
Showing posts with label Power. Show all posts
Tuesday, 8 November 2011
Show-TimeSpan.ps1
Labels:
Power,
PowerShell scripts,
system.datetime,
System.TImespan
Monday, 14 February 2011
New-Shortcut.ps1
- <#
- .SYNOPSIS
- This script creates a shortcut to Notepad on the Desktop
- .DESCRIPTION
- This script creates a Wscript.shell item, then creates
- a shortcut on the desktop to Notepad.exe.
- .NOTES
- File Name : New-Shortcut.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINKS
- This post is a re-implementation of an MSDN Script
- http://msdn.microsoft.com/en-us/library/0ea7b5xe%28VS.85%29.aspx
- Posted to Powershell Scripts Blog
- HTTP://Pshscripts.blogspot.com
- .EXAMPLE
- Left as an exercise for the reader
- #>
- # create wscript object
- $WshShell = New-Object -com Wscript.Shell
- #Get Desktop location
- $Desktop = $WshShell.SpecialFolders.item("Desktop")
- # create a new shortcut
- $ShellLink = $WshShell.CreateShortcut($Desktop + "\Shortcut Script.lnk")
- $ShellLink.TargetPath = $WScript.ScriptFullName
- $ShellLink.WindowStyle = 1
- $ShellLink.Hotkey = "CTRL+SHIFT+F"
- $ShellLink.IconLocation = "notepad.exe, 0"
- $ShellLink.Description = "Shortcut Script"
- $ShellLink.WorkingDirectory = $Desktop
- #Save the link to the desktop
- $ShellLink.Save()
Labels:
Power,
PowerShell scripts,
Wscript.Shell
Tuesday, 29 June 2010
Remove-XMLAttribute.ps1
- <#
- .SYNOPSIS
- This script removes an an attribute from an XML element.
- .DESCRIPTION
- This script creates an XML document, then removes an
- Attribute using the RemoveAttribute method.
- .NOTES
- File Name : Remove-XMLAttribute.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/z267hx58.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Remove-XMLAttribute.ps1
- Display the initial XML...
- <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book>
- Display the modified XML...
- <book ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book>
- #>
- # Create and load an XML Document
- $Doc = New-Object System.Xml.XmlDocument
- $Doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
- "<title>Pride And Prejudice</title>" +
- "</book>")
- # Set root
- $Root = $Doc.DocumentElement
- # Display initial XML
- "Display the initial XML..."
- $Doc.InnerXml
- # Remove the genre attribute
- $Return = $Root.RemoveAttribute("genre")
- # Display result
- "Display the modified XML..."
- $Doc.InnerXml
Labels:
Power,
powershell,
PowerShell scripts,
System.XML.XMLDocument
Subscribe to:
Posts (Atom)