• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Clatent

Technology | Fitness | Food

  • About
  • Resources
  • Contact

One-Liner Wednesday December 21, 2022

December 21, 2022 by ClaytonT Leave a Comment

It’s Wednesday, so you know what that means? A new one liner that I’m hoping is useful for you as it has been useful for me. I’ve talked about date and time before, but that was for selecting dates. What about if you wanted to figure out how many days till the end of the year, or how many seconds from current time to 3 months and 5 days from now is? Or when the last time a file was modified?

New-TimeSpan is your answer. Want to know how many days and seconds it is till the end of the year?

New-Timespan -end 12/31/2022

You can use the -Start parameter but isn’t needed unless you want to use a different start date.

What about if you only need the days because you will be putting it into a variable to use later on?

New-TimeSpan -end 12/31/2022 | select days

The final one I’ll leave you with is:

Get-ChildItem $PSHOME\onelinerwednesday.ps1 | New-TimeSpan

This will tell you the last time the file was updated. This can be great if you have scheduled tasks that run or if you need to find files that were edited in the last 3 hours or 3 years. This can also be used on any command that uses the -LastWriteTime property.

Let me know if you have used this before or what you intend to try it out on.

Related

Tagged With: One Liner Wednesday, PowerShell

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recipe Rating




Primary Sidebar

Clayton Tyger

Tech enthusiast dad who has lost 100lbs and now sometimes has crazy running/biking ideas. Read More…

Find Me On

  • Email
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter

Recent Posts

  • One-Liner Wednesday January 25, 2023
  • Module Monday January 23, 2023
  • One-Liner Wednesday January 18, 2023
  • Module Monday January 16, 2023
  • Read-Only Friday January 13, 2023

Categories

  • 365
  • Active Directory
  • Cim
  • Dashboards
  • Documentation
  • Get-WMI
  • Learning
  • Module Monday
  • Nutanix
  • One Liner Wednesday
  • Passwords
  • PDF
  • PowerShell
  • Read-Only Friday
  • Reporting
  • Security
  • Windows
  • WSUS

© 2023 Clatent