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; it should be…

0

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 reliably.  My solution is to arbitrarily rule that if the timestamps are within…

0

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. -AsObject returns the…

0

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 = {$i; $null = $global:i++ }}, @{name = ‘output’;…

2

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’).LastBootUpTime20090712112652.125000-420 So, we have this ugly string.  Hhow do we convert it to something we can use (namely, a string…

0

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’).LastBootUpTime20090712112652.125000-420 The output is a little hard to read.  PSH> $lastBootUpTimeWMIObject = (Get-WmiObject -Query ‘SELECT…

0