PowerTip: Use PowerShell to Find Changed Directories

PowerTip: Use PowerShell to Find Changed Directories

  • Comments 4
  • Likes

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')}

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Q: How can I use Windows PowerShell to find files that have changed since a specific date?

    A:

       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')}

  • 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.

  • @@ 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.

    Example:

    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,

  • Sorry for the type:

    <alias> ->

    Should be:

    <alias> -?