BRONZE PARTNER:
BRONZE PARTNER:
Industry News:

| |
| |
 |
 |
 |
 |
 |
| PowerShell Convert To Date Time Method |
 |
|
|
By: Don Hite
Posted On: 7/16/2007
This article was Previously posted on Don Hite's Blog
This post will briefly describe PowerShell’s convert to date time method and offer you an example of how to use it in your scripts.
When you execute the following to return the last boot up time for the operating system: GWMI –Cl Win32_OperatingSystem –Prop LastBootUpTime The output is displayed as
__GENUS : 2 __CLASS : Win32_OperatingSystem __SUPERCLASS : __DYNASTY : __RELPATH : __PROPERTY_COUNT : 1 __DERIVATION : {} __SERVER : __NAMESPACE : __PATH : LastBootUpTime : 20070601081252.500000-300
The LastBootUpTime is not stored in an encrypted code it is a readable format if you know how to decipherer the Keys or you can just convert them within your script. You can convert this time to a readable format using PowerShell’s ConvertToDateTime method as in the example below:
$Don = GWMI -Cl Win32_OperatingSystem $Don.ConvertToDateTime($Don.LastBootUpTime)
Here the output is displayed as: Friday, June 01, 2007 8:12:52 AM
PowerShell processes the last boot up time as follows:
DayOfWeek : Friday DayOfYear : 152 Hour : 8 Millisecond : 500 Minute : 12 Month : 6 Second : 52 Ticks : 633162823725000000 TimeOfDay : 08:12:52.5000000 Year : 2007
Which in the case of my XP workstation is: Friday, June 01, 2007 8:12:52 AM
For more information on time and date conversions for your VBS scripts and SQL queries see the following previously published posts:
Converting Coordinated Universal Time Script Dates To A Readable Format http://myitforum.com/cs2/blogs/dhite/archive/2007/05/13/converting-coordinated-universal-time-script-dates-to-a-readable-format.aspx
Converting SQL Table SMS Timestamps To Readable Formats For SQL Queries http://myitforum.com/cs2/blogs/dhite/archive/2007/05/02/converting-sql-table-sms-timestamps-to-readable-formats-for-sql-queries.aspx
|
 |
 |
 |
|
|