Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. function ConvertFrom-DwordDate([int32]$DwordValue) {
  2. #Ex. $DwordValue = 132055314
  3. #Convert to hex with 8 chars (16bit year + 8bit month + 8bit day)
  4. $hex = $DwordValue.ToString('X8')
  5. #Ex. $hex = 0x07df0112 = 0x07df(year) 0x01 (month) 0x12 (day)
  6.  
  7. #Convert to date string
  8. $datestring = '{0:D4}\{1:D2}\{2:D2}' -f [convert]::ToUInt32($hex.Substring(0,4),16), [convert]::ToUInt32($hex.Substring(4,2),16), [convert]::ToUInt32($hex.Substring(6,2),16)
  9. #Convert to datetime and output
  10. $datetime = [datetime]::ParseExact($datestring,'yyyy\\MM\\dd',$null)
  11. #Output
  12. $datetime
  13. }
  14.  
  15. function ConvertTo-DwordDate([datetime]$Date = (Get-Date)) {
  16. #Convert to combined hex
  17. $combinedhex = '{0:X}{1:X2}{2:X2}' -f $Date.Year, $Date.Month, $Date.Day
  18. #Convert to decimal
  19. $decimal = [convert]::ToUInt32($combinedhex,16)
  20. #Ouput
  21. $decimal
  22. }
  23. $MyInvocation.MyCommand.Name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement