Keith's profileKeith Hill's BlogPhotosBlogListsMore Tools Help
    December 11

    Little Things in PowerShell - Determine Timespan of Files in a Dir

    Often it is the "little things" that put a smile on your face.  PowerShell does that for me a lot.  Take for instance a simple little problem I ran into today while unit testing some code that generates log files.  I wanted to know how long it took to write all the log files to disk.  Due to the way the code works on a background thread, it wasn't particularly easy to use a System.Diagnostics.Stopwatch to do this.  You could do this manually by inspecting the file dates (DateCreated and DateModified) in Windows Explorer but it only shows resolution down to minutes and I have to do the math myself.  No good.  Well this information is easy to figure out with PowerShell.  Just CD into the log dir and execute:

    PS> $start = dir | foreach {$_.CreationTime} | sort | select -first 1
    PS> $stop  = dir | foreach {$_.LastWriteTime} | sort -desc | select -first 1
    PS> $stop - $start

    Days              : 0
    Hours             : 0
    Minutes           : 0
    Seconds           : 10
    Milliseconds      : 734
    Ticks             : 107341689
    TotalDays         : 0.000124238065972222
    TotalHours        : 0.00298171358333333
    TotalMinutes      : 0.178902815
    TotalSeconds      : 10.7341689
    TotalMilliseconds : 10734.1689

    :-)

    Yes PowerShell can do all sorts of acrobatics WRT managing and querying a computer but it can also do the simple stuff in a pretty straight forward manner.

    December 01

    Windows PowerShell Training Webcast

    Sign up for some free PowerShell training via this TechNet webcast.  Here’s the overview:"

    In this webcast, we provide an introduction to Windows PowerShell for IT professionals and show how to automate client administrative activities in the Windows Server 2008 and Windows Vista operating systems. We explore the features and capabilities of Windows PowerShell, describe customer scenarios to manage day-to-day server and client administration activities, and discuss command-line syntax usage.

    Presenters: John Baker, IT Pro Evangelist, Microsoft Corporation, and Yung Chou, IT Pro Evangelist, Microsoft Corporation

    I like these because you usually get some decent info for very little investment and if it doesn’t turn out to be right for you, you can bail easily with very little time lost.