Lessons Learned

My drop-site for interesting snippets and tips. If it's useful to you as well, great!

Browse by Tags

Tagged Content List
  • Blog Post: Parsing Dates by Hand

    I’m always impressed by the amount of variety in input formats that Get-Date can accept and still parse it into a date. However, there is one time that it vexes me: US vs. EU date strings.  Specifically, the US uses dd/MM/[yy]yy, while the EU uses MM/dd/[yy]yy.  In my mind, neither make sense;...
  • Blog Post: Testing Timestamps of Files Across a Slow Network

    I’m not sure if this is because of network lag, or the fact that my lab is on a different AD domain (and different NTP clock) than my local computer.  All I know is: (Get-Item local\path\to\OriginalFile.txt).LastWriteTime –eq (Get-Item remote\path\to\CopyOfFile.txt).LastWriteTime Does not work...
  • Blog Post: Adding a Timestamp to a Pipeline of Strings

    If I'm doing something long-running, and I want it to know when various lines of output are generated, assuming they are being sent to STDOUT (something PSH is NOT good at), here's a quick way to preface the output with a timestamp. -Format allows us to pass a formatting parameter to Get-Date. ...
  • Blog Post: One-Liner: GetDateTimeFormats

    DateTime objects are amazing. You can format them in so many different ways, but they also come with a boatload formats pre-defined. Oh, and it uses the current culture. So much cleaner. But which is which? $i = 0; ( Get-Date ).GetDateTimeFormats() | Select-Object @{name = 'index' ; expression = ...
  • Blog Post: PowerShell for Non-N00bs: Formatting Time With RegEx

    So, last episode we learned how to format the output of a LastBootUpTime property from the WIN32_OperatingSystem WMI query to something human readable using WMI. What if that didn't exist? PSH> (Get-WmiObject -Query 'SELECT LastBootUpTime FROM Win32_OperatingSystem').LastBootUpTime 20090712112652...
  • Blog Post: PowerShell for Non-N00bs: System Uptime Via WMI

    Getting the last time a system was rebooting is pretty easy from WMI. From this half-decade old post , we get the two key bits: the LastBootUptTimem property of the Win32_OperatingSystem WMI class. In PowerShell, it looks like this: PSH> (Get-WmiObject -Query 'SELECT LastBootUpTime FROM Win32_OperatingSystem...
Page 1 of 1 (6 items)