Active Directory Powershell: Quick Tip LastLogonTimeStamp And ...

  • Login
    • Account
    • Sign Up
  • Home
    • About Us
    • Catalog
  • Search
  • Register RSS
  • Embed RSS
    • FAQ
    • Get Embed Code
    • Example: Default CSS
    • Example: Custom CSS
    • Example: Custom CSS per Embedding
  • Super RSS
    • Usage
    • View Latest
    • Create
  • Contact Us
    • Technical Support
    • Guest Posts/Articles
    • Report Violations
    • Google Warnings
    • Article Removal Requests
    • Channel Removal Requests
    • General Questions
    • DMCA Takedown Notice
  • RSSing>>
    • Collections:
    • RSSing
    • EDA
    • Intel
    • Mesothelioma
    • SAP
    • SEO
  • Latest
    • Articles
    • Channels
    • Super Channels
  • Popular
    • Articles
    • Pages
    • Channels
    • Super Channels
  • Top Rated
    • Articles
    • Pages
    • Channels
    • Super Channels
  • Trending
    • Articles
    • Pages
    • Channels
    • Super Channels
Switch Editions? Cancel Sharing: Title: URL: Copy Share URL English RSSing.com RSSing>> Latest Popular Top Rated Trending Channel: TechNet Blogs NSFW? Claim 0 X Mark channel Not-Safe-For-Work? cancel confirm NSFW Votes: (0 votes) X Are you the publisher? Claim or contact us about this channel. X 0 Showing article 28470 of 36188 in channel 4753999 Channel Details:
  • Title: TechNet Blogs
  • Channel Number: 4753999
  • Language: English
  • Registered On: September 15, 2012, 2:07 pm
  • Number of Articles: 36188
  • Latest Snapshot: June 23, 2019, 12:42 am
  • RSS URL: http://blogs.technet.com/b/mainfeed.aspx?type=blogsonly
  • Publisher: https://blogs.technet.microsoft.com
  • Description: Get the latest information, insights, announcements, and news from Microsoft experts and IT...
  • Catalog: //technet239.rssing.com/catalog.php?indx=4753999
Remove ADS Viewing all articles First Article ... Article 28468 Article 28469 Article 28470 Article 28471 Article 28472 ... Last Article Browse latest Browse all 36188 ↧ $ 0 0

 

Here is a quick tip on how to quickly convert properties like LastLogonTimeStamp and pwdLastSet into readable results in your PowerShell Script.

Here is the problem, when running commands like get-aduser or get-adcomputer, results of fields are unreadable and require additional formatting in order to read.

Example:

get-aduser chad -properties lastlogontimestamp,pwdLastSet | select samaccountname, lastlogontimestamp,pwdLastSet

image

There are several blogs on how to use a calculated property to convert and display the results, that is not the purpose of this blog entry. For me I usually forget how to do this (older I get the less I remember) and have to review previous scripts on how to do this each time I write one.  I also usually write bigger scripts were I have to perform this same conversion multiple times, which causes my script to grow in size and makes it a little more difficult to read.

This is how most articles and blogs do this conversion.

Example:

get-aduser chad -properties lastlogontimestamp,pwdLastSet | select samaccountname, ` @{Name="LastLogonTimeStamp";Expression={([datetime]::FromFileTime($_.LastLogonTimeStamp))}},` @{Name="pwdLastSet";Expression={([datetime]::FromFileTime($_.pwdLastSet))}}

image

Now keep in mind copying and pasting this over and over isn't that hard.  But I’m going to provide a way to define it once in a script and then just reference it as needed. In additional going to provide a way to add this to PowerShell ISE as a snippet so that it can be added in a script as needed.

Here is the solution, store the calculated property hash into a variable, reference the variable instead of the entire hash.

Example:

$hash_lastLogonTimestamp = @{Name="LastLogonTimeStamp";Expression={([datetime]::FromFileTime($_.LastLogonTimeStamp))}} $hash_pwdLastSet = @{Name="pwdLastSet";Expression={([datetime]::FromFileTime($_.pwdLastSet))}}   get-aduser chad -properties lastlogontimestamp,pwdLastSet | ` select samaccountname, $hash_lastLogonTimestamp,$hash_pwdLastSet

image

Using the variable I can define this once and reuse it through out a script or the PowerShell cli

Example:

$hash_lastLogonTimestamp = @{Name="LastLogonTimeStamp";Expression={([datetime]::FromFileTime($_.LastLogonTimeStamp))}} $hash_pwdLastSet = @{Name="pwdLastSet";Expression={([datetime]::FromFileTime($_.pwdLastSet))}}   get-aduser chad -properties lastlogontimestamp,pwdLastSet | ` select samaccountname, $hash_lastLogonTimestamp,$hash_pwdLastSet get-adcomputer corp-apps -properties lastlogontimestamp,pwdLastSet | ` select samaccountname, $hash_lastLogonTimestamp,$hash_pwdLastSet get-aduser ryan -properties lastlogontimestamp,pwdLastSet | ` select samaccountname, $hash_lastLogonTimestamp,$hash_pwdLastSet get-adcomputer corp-web01 -properties lastlogontimestamp,pwdLastSet | ` select samaccountname, $hash_lastLogonTimestamp,$hash_pwdLastSet

image

For those that use PowerShell ISE,  make this something to easily reference by using ise snippets.  More Information

Here is that cmdlets to run in ISE to make this a snippet:

New-IseSnippet -Description "Convert Active Directory property LastLogonTimestamp" ` -Text '$hash_lastLogonTimestamp = @{Name="LastLogonTimeStamp";Expression={([datetime]::FromFileTime($_.LastLogonTimeStamp))}}' ` -Title "Convert LastLogonTimeStamp" -Author "Chad"   New-IseSnippet -Description "Convert Active Directory property pwdLastSet" ` -Text '$hash_pwdLastSet = @{Name="pwdLastSet";Expression={([datetime]::FromFileTime($_.pwdLastSet))}}' ` -Title "Convert pwdLastSet" -Author "Chad"

 

In Powershell ISE, put the cursor on the line where the snippet needs to go, Press Ctrl + j and then select the newly created snippet.

image

Just like that no longer do I have to look through previous scripts.

That is all I have for now, Hope you find this useful.

-Chad

↧ Search RSSing.com Remove ADS Viewing all articles First Article ... Article 28468 Article 28469 Article 28470 Article 28471 Article 28472 ... Last Article Browse latest Browse all 36188

Trending Articles

RAMAYAMPET Mandal Sarpanch | Upa-Sarpanch | Ward member Mobile Numbers Medak...

May 24, 2017, 2:00 am

लड़कियां सेक्स के दौरान क्यों करती है उह! आह!लड़कियां सेक्स के दौरान क्यों करती...

May 19, 2016, 1:54 am

Neem Baba Extra Questions Answer Class 6 English Poorvi

February 1, 2025, 5:19 am

Throw Back: 4×4 — Sikilitele (Ft Castro) Prod by JQ

March 5, 2015, 8:24 am

Rajasthan Board 10th Result 2016 Roll No wise & Name Wise

August 20, 2016, 5:13 pm

Lowe faces four theft charges

November 14, 2017, 6:52 pm

Practice Sheet of Right form of verbs for HSC Students

September 22, 2019, 11:40 pm

Mafia, Murder & Mayhem In The Motor City: Detroit Mob Hit Timeline (1937-2007)

December 7, 2016, 3:57 pm

The 10 Tennessee Cities With The Largest Black Population For 2021

December 21, 2020, 10:12 am

Materials Around Us Class 6 Worksheet Science Chapter 6

October 3, 2024, 5:20 am

デスクトップ ヒープの枯渇

January 18, 2018, 8:31 pm

Best Suvichar in Hindi |बेस्ट सुविचार |शुभ विचार हिंदी में

March 7, 2020, 11:19 pm

Kanulanu Thaake Lyrics and translation | Manam (2014)

May 9, 2014, 5:45 am

Korean Sex Porn Videos: XXX Videos & Free Porn Movies

May 30, 2025, 9:29 pm

Teen Shot In Miami Drive-By Dies From Injuries

August 8, 2011, 1:16 pm

Download: IQ Muzatasha feat Shy D & Pmj – Ulesi NiFertilizer Yamavuto

March 22, 2018, 7:23 pm

Mahakal Attitude Status

February 29, 2020, 9:52 am

Property developer set up cannabis factory to help pay off debts...

August 3, 2015, 2:29 am

July 11, 2015, 6:15 am

KB: How to troubleshoot issues when adding a Hyper-V host in System Center...

August 14, 2012, 10:05 am Search RSSing.com
  • RSSing>>
  • Latest
  • Popular
  • Top Rated
  • Trending
© 2026 //www.rssing.com <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>

Tag » Active Directory Pwdlastset Convert To Date Powershell