Active Directory Powershell: Quick Tip LastLogonTimeStamp And ...
Maybe your like
- 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
- 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
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
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))}}
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
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
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.
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 36188Trending Articles
RAMAYAMPET Mandal Sarpanch | Upa-Sarpanch | Ward member Mobile Numbers Medak...
May 24, 2017, 2:00 amलड़कियां सेक्स के दौरान क्यों करती है उह! आह!लड़कियां सेक्स के दौरान क्यों करती...
May 19, 2016, 1:54 amNeem Baba Extra Questions Answer Class 6 English Poorvi
February 1, 2025, 5:19 amThrow Back: 4×4 — Sikilitele (Ft Castro) Prod by JQ
March 5, 2015, 8:24 amRajasthan Board 10th Result 2016 Roll No wise & Name Wise
August 20, 2016, 5:13 pmLowe faces four theft charges
November 14, 2017, 6:52 pmPractice Sheet of Right form of verbs for HSC Students
September 22, 2019, 11:40 pmMafia, Murder & Mayhem In The Motor City: Detroit Mob Hit Timeline (1937-2007)
December 7, 2016, 3:57 pmThe 10 Tennessee Cities With The Largest Black Population For 2021
December 21, 2020, 10:12 amMaterials Around Us Class 6 Worksheet Science Chapter 6
October 3, 2024, 5:20 amデスクトップ ヒープの枯渇
January 18, 2018, 8:31 pmBest Suvichar in Hindi |बेस्ट सुविचार |शुभ विचार हिंदी में
March 7, 2020, 11:19 pmKanulanu Thaake Lyrics and translation | Manam (2014)
May 9, 2014, 5:45 amKorean Sex Porn Videos: XXX Videos & Free Porn Movies
May 30, 2025, 9:29 pmTeen Shot In Miami Drive-By Dies From Injuries
August 8, 2011, 1:16 pmDownload: IQ Muzatasha feat Shy D & Pmj – Ulesi NiFertilizer Yamavuto
March 22, 2018, 7:23 pmMahakal Attitude Status
February 29, 2020, 9:52 amProperty developer set up cannabis factory to help pay off debts...
August 3, 2015, 2:29 am♡
July 11, 2015, 6:15 amKB: 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
Tag » Active Directory Pwdlastset Convert To Date Powershell
-
Get-AdUser PwdLastSet - Get Aduser Last Password Change
-
Efficiently Converting Pwdlastset To Datetime In A Single Line.
-
Converting Pwdlastset To Datetime Datatype Not Working From Hash ...
-
Powershell Output Of Ad-user PwdLastSet And LastLoginTimeStamp
-
PowerShell Code: Convert Integer8 To Date - Active Directory Security
-
TIP: Active Directory Module Date Properties - Tech Wizard
-
Powershell: How Do I Query PwdLastSet And Have It Make Sense?
-
Convert Int64 TimeStamp To DateTime In Powershell
-
LDAP, Active Directory & Filetime Timestamp Converter
-
Powershell Script - Users Pwdlastset - Spiceworks Community
-
Finding Users Who Have Not Changed Their Password Recently
-
How To Find Last Password Change Date With Or Without PowerShell
-
How To Convert Active Directory TimeStamp Property To DateTime
-
Integer8 Attributes