Sunday, April 10, 2016

Powershell v2 Locate Folders with LastWriteTime Before Today

A system process runs each night to condense folders on a share into one folder each night.  Last night it appeared to have not run . To verify I came up with this script:
dir mysharec$data** eports* | `
Where { $_.LastWriteTime -lt (Get-Date -Format MM-dd-yyyy) } | `
% { Split-Path $_.fullname } | `
Group | `
Where { $_.Count -gt 1 } | `
select name
This script does a few things:
  1. Looks for folders at a specific depth without having to recurse by using wildcards
  2. Filters the folders so only folder last written to yesterday (or earlier) are returned
  3. Gathers the main folder path with Split-Path against the pipelined Directory object
  4. Groups the objects
  5. Filters on groups to return collections (2 or more)
  6. Selects name only
Using this approach I can narrow down my search to exactly what I need to look at without manually touching anything.

Related Post:

0 comments:

Post a Comment

 
Copyright 2009 Information Blog
Powered By Blogger