All very valid points. I have mixed feelings regarding aliases. On the one
hand I generally avoid then in script files. I think they would make
maintenance difficult since there is no guarantee that they will always
exist. At the command line I use them extensively. As for posting in threads,
I think that while it could be confusing to someone who doesn't know them,
how else will they learn about them? I didn't know ? = Where-Object until I
saw it in a blog post one time. Generally I do avoid them in posts. What I
will do is work out the answer at the command line using aliases then post
the line without the alias. (Hey, that would be a nice function. You hand it
a string and it gives the string back with all the aliases replaced by the
actual command.) In this case I was just being lazy and did a copy and paste.
Also, not to be pedantic, but you used an alias as well (where).
As for .LastAccessTime vs. .LastWriteTime I suppose it would depend on the
original poster's need. When I look at archive scripts I usually don't care
how long it has been since someone looked at the file, I just care about the
last time that someone made a change to the file. Although the other view is
just as (and perhaps more) valid.
So here is my suggestion with the proposed changes:
get-childitem | where-object{((get-date).Subtract($_.LastAccessTime).Days
-gt 45)}
"Brandon Shell" wrote:
> Sup Ebgreen... just some helpful hints.
>
> - When posting stuff for other people I try to avoid alias (I know, I
> know... it is super hard)
>
> - Not sure you know, but system.datetime has a few methods you can add
> negative numbers to that are quite useful
> AddDays
> AddHours
> AddMilliseconds
> AddMinutes
> AddMonths
> AddSeconds
> AddTicks
> AddYears
>
> - For access time I would use .LastAccessTime instead LastWriteTime
>
> "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
> news:F6E82F07-5945-4770-85E6-2792466373C3@microsoft.com...
> > Here is a quick one-liner that will hopefully point you in the right
> > direction. It should list all the files and folders that were accessed
> > more
> > than 45 days ago:
> >
> > ls | ?{((get-date).Subtract($_.LastWriteTime).Days -gt 45)}
> >
> > "frank" wrote:
> >
> >> I was wondering if any has a script that will check an e: drive directory
> >> and
> >> subdirctory but only listthe directory and files that are older then 3
> >> months
> >>
> >>
> >> thanks
> >>
> >>
> >>
> >> frank
>
>