convert output to human readable format

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 9 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

convert output to human readable format

Post by daviesg6 »

I have created a Primal forms GUI for the 1st line team, until now they had no access to things like if a users password had expired, when it was last set etc. Everything works fine, apart from the output for the lastlogon attribute is just a numeric string yet the output for PasswordLastSet is a readable date format.

The script providing this output is
PowerShell Code
Double-click the code block to select all.
$results.Text=Get-ADUser -Filter "DisplayName -eq '$($EntryBox.text)'" -Properties DisplayName, sAMAccountName, mail, lastlogon, extensionattribute5, PasswordLastSet, PasswordExpired, PasswordNeverExpires, buMemberOf, msExchOmaAdminWirelessEnable | Out-String
    $results.Focus()
$results is the output window
$EntryBox is the text field the 1st line guys enter the users name into

The output I receive is (the 2 date outputs are highlighted in red)

buMemberOf : {Gartner, Library Patron, Current Employee}
DisplayName : Jihn Doe
DistinguishedName : CN=John Doe,OU=OU,DC=domain,DC=com
Enabled : True
GivenName : John
lastlogon : 130607135752597276
mail : jdoe@domain.com
Name : John Doe
ObjectClass : user
ObjectGUID : d5244bee-482f-4558-a260-9cc47a8627fb
PasswordExpired : False
PasswordLastSet : 10/23/2014 8:53:59 AM
PasswordNeverExpires : False
SamAccountName : jdoe
SID : S-1-5-21-1202660629-117609710-682003330-38660
Surname : Doe
UserPrincipalName : jdoe@domain.com

Wht are these different, they are both date fields in AD, and how can I make lastlogon a useful/readable attribute in this script?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: convert output to human readable format

Post by jvierra »

Use LastLogonDate. It is a pre-converted date object and will display like a date.
User avatar
daviesg6
Posts: 49
Last visit: Tue Nov 25, 2014 1:23 pm

Re: convert output to human readable format

Post by daviesg6 »

thanks, I knew it would be a simple fix
This topic is 9 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked