PowerTip: Use PowerShell to Find Changed Directories

Summary: Use Windows PowerShell to identify directories that changed since a specific date.

Hey, Scripting Guy! Question How can I use Windows PowerShell to find directories that have changed since a specific date?

Hey, Scripting Guy! Answer Use the Get-ChildItem cmdlet and specify only directories. Pipe the results to Where-Object and evaluate the LastWriteTime property (dir is an alias for Get-ChildItem? is an alias for Where-Object).

Windows PowerShell 3.0 syntax:

dir -Directory | ? lastwritetime -gt $([datetime]’4/1/2013′)

Windows PowerShell 2.0 syntax:

dir | ? { $_.psiscontainer -AND $_.Lastwritetime -gt $([datetime]’4/1/2013′)}

Comments (4)

  1. Maybe I'm being picky but I think it'd be helpful to show a version without aliases.  When I was starting out they confused the heck out of me.

  2. jrv says:

    @@ R Jason Morgan

    You know how this on goes….

    Any alias:

    <alias> ->

    This will always decode the alias.

    dir -?

    gci -?

    ls -?

    We can even include a whole line when we have a doubt. If you don't like cancelling a long line because you need to look up a parameter then just add -? hit enter and help will  be displayed.  Up arrow and edit the saved line.

    Works inV2 and V3.


    dir c:Windows -Directory -Filter *sys* -Recurse -?

    Really helpful on long gwmi lines with BIG filters or with Get-WinEvent with a very long FilterXPath statement,

  3. jrv says:

    Sorry for the type:

    <alias> ->

    Should be:

    <alias> -?

  4. Krunch {The Commenter formerly known as K} says:

    Q: How can I use Windows PowerShell to find files that have changed since a specific date?


       PoSh 3.0 syntax:

       gci -file | ? lastwritetime -gt $([datetime]'4/1/2013')

       PoSh 2.0 syntax:

       gci | ?{ $_.Directory -AND $_.Lastwritetime -gt $([datetime]'4/1/2013')}