• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

directory and file date

B

Brandon Shell

#1
Try this. I assumed you meant last changed.
get-childitem e: -recurse | where{$_.LastWriteTime -lt
(([datetime]::now).Addmonths(-3))}


"frank" <frank@discussions.microsoft.com> wrote in message
news:48C96B5F-970B-428F-883C-02D7DAFB8178@microsoft.com...
>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
 

My Computer

F

frank

#2
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
 

My Computer

E

ebgreen

#3
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
 

My Computer

B

Brandon Shell

#4
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
 

My Computer

E

ebgreen

#5
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

>
>
 

My Computer

B

Brandon Shell

#6
Are you writting this one :)

"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). :)"


"ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
news:2A87B130-D20D-4A85-A35A-118BE06EF235@microsoft.com...
> 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

>>
>>
 

My Computer

S

Shay Levi

#7
>> Hey, that would be a nice function...
I think it exists in PrimalScript 2007 :)

As for writing posts with aliases, you can always add a comment like

# ? = where-object
# % = foreach-object
dir . | % {some code}


Shay
http://scriptolog.blogspot.com



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

My Computer

E

ebgreen

#8
I've given it some thought and for the time being, no. :) It would actually
have to be a fairly complex recursive descent parser and I don't have that
much free time.

"Shay Levi" wrote:

> >> Hey, that would be a nice function...

> I think it exists in PrimalScript 2007 :)
>
> As for writing posts with aliases, you can always add a comment like
>
> # ? = where-object
> # % = foreach-object
> dir . | % {some code}
>
>
> Shay
> http://scriptolog.blogspot.com
>
>
>
> > 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
> >>>>

>
>
>
 

My Computer

E

ebgreen

#9
Ooops...replied to the wrong post. My post immediately above should be here.

"Brandon Shell" wrote:

> Are you writting this one :)
>
> "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). :)"
>
>
> "ebgreen" <ebgreen@discussions.microsoft.com> wrote in message
> news:2A87B130-D20D-4A85-A35A-118BE06EF235@microsoft.com...
> > 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
> >>
> >>

>
>
 

My Computer

R

RichS

#10
I did started something like that a few weeks back. See

http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!543.entry

--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"ebgreen" wrote:

> 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

> >
> >
 

My Computer

E

ebgreen

#11
That is really nice. Thank you for sharing. I assumed that there must be a
way to get the engine to do the parsing for you, I was just too lazy to
figure it out.

"RichS" wrote:

> I did started something like that a few weeks back. See
>
> http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!543.entry
>
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "ebgreen" wrote:
>
> > 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
> > >
> > >
 

My Computer

H

Hal Rottenberg

#12
On Aug 23, 5:07 pm, Shay Levi <n...@addre.ss> wrote:
> As for writing posts with aliases, you can always add a comment like
>
> # ? = where-object
> # % = foreach-object
> dir . | % {some code}


# dir = Get-ChildItem

Forgot one, LOL!
 

My Computer

S

Shay Levi

#13
Well, I took up the gauntlet ;)

Here's a the first working code, I didn't test it extensively.
Can you check it on your scripts?


function Convert-CmdletToAlias{
param([string]$filepath)

if(!(test-path $filepath)){
write-warning "Error: File doesnt exist";
break;
}

$src = [System.IO.File]::ReadAllText($filepath);
$cmdlets = get-command | where {$_.CommandType -eq "Cmdlet"} | select name
# where {$_.CommandType -eq "Cmdlet" -and $_.PSSnapIn.name -like "Microsoft.PowerShell*"}
$cmdlets | foreach {

$cmd = $_.name;

if($src -match "\s`?$cmd\s") {
$alias = @(get-alias | where {$_.definition -eq $cmd});
$src=$src -replace($cmd,$alias[0]);
}
}

$src;
}

function Convert-AliasToCmdlet{

param([string]$filepath)

if(!(test-path $filepath)) {
write-warning "Error: File doesnt exist";
break;
}

cls
$src = [System.IO.File]::ReadAllText($filepath);
$aliases = get-alias | select Name,Definition

$aliases | foreach {

$alias = @($_)[0];
$name=$alias.name;
$def=$alias.definition;

trap{write-host "ERROR cant process alias: <$alias> -f red -b black"; continue}

$regex=[regex]::escape($name);
if($src -match "\s" +$regex +"\s"){
$src=$src -replace([regex]::escape($name),$def);
}
}

$src;
}

#################################

BTW, stumbled on a weird thing. Getting the alias for foreach-object is working
fine

PS C:\Scripts> get-alias -name "%"

CommandType Name Definition
----------- ---- ----------
Alias % ForEach-Object


Shouldnt this return only where-object?

get-alias -name "?"
-or-
get-alias -name '?'

It returns 4 differnet aliases

CommandType Name Definition
----------- ---- ----------
Alias % ForEach-Object
Alias ? Where-Object
Alias h Get-History
Alias r Invoke-History

Only this return the expected

PS C:\Scripts> get-alias | where {$_.name -eq "?"}

CommandType Name Definition
----------- ---- ----------
Alias ? Where-Object




Shay
http://scriptolog.blogspot.com



> Are you writting this one :)
>
> "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). :)"
> "ebgreen" <ebgreen@xxxxxx> wrote in message
> news:2A87B130-D20D-4A85-A35A-118BE06EF235@xxxxxx
>

>> 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@xxxxxx> wrote in message
>>> news:F6E82F07-5945-4770-85E6-2792466373C3@xxxxxx
>>>
>>>> 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
>>>>>
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)