convert lastlogon date value (1/1/1970) RRS feed

  • Question

  • how to convert lastlogon value

    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkLoginProfile")
    Dim objLastLogon

    ForEach objItemin colItems
    if (objItem.UserType = "Normal Account") Then

    Wscript.Echo objItem.Name & " " & objItem.LastLogon


    Monday, August 4, 2014 10:35 AM


All replies

  • Here is the converter with examples: http://msdn.microsoft.com/en-us/library/aa393687(v=vs.85).aspx


    • Proposed as answer by jrv Monday, August 4, 2014 10:58 AM
    Monday, August 4, 2014 10:49 AM
  • Thx for feedback.

    not able to convert this value (20140803215615.000000+180)


    Monday, August 4, 2014 10:55 AM
    • Marked as answer by ScriptingWife Tuesday, September 16, 2014 7:16 PM
    Monday, August 4, 2014 4:43 PM
  • Sorry but it is turnkey.  We convert WMI dates using the converter class for WMI dates.  These are built into every class in PowerShell by the framework.  In other scripts we have to create the converter.  The link I posted shows exactly how to do this:

    Set wbemDate = CreateObject("WbemScripting.SWbemDateTime")

    Now just assign the string to it and extract whatever type of date you want.

    wbemDate.Value = wmi.LastLogon

    Now you have a date object.  TO get a windows date we do this:

    dt = wbemDate.GetVarDate()

    WScript.Echo dt

    You can mange timezone and get or set a file time.

    Manual manipulation of the string has not been needed with WMI since at least W2K SP4.


    Monday, August 4, 2014 4:55 PM
  • Sorry but it is turnkey. 

    The link I posted isn't.

    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    Monday, August 4, 2014 4:58 PM
  • For some reason the converters in WMI seem to get ignored.  I always hated thee string manipulation and had built a better converter.  As soon as I do Microsoft released the WMI update.

    I only posted the link because I believe it is good experience for anyone to actually look at the full documentation as there is much to discover.


    Monday, August 4, 2014 5:05 PM