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

Find files

A

acatejr@gmail.com

#1
Hi,

I am very new to using PowerShell. I would like it to search for files
on a drive that are of a certain size and created between two specific
dates. If anyone can help I'd be grateful. Thanks in advance.
 

My Computer

M

Marco Shaw

#2
> I am very new to using PowerShell. I would like it to search for files
> on a drive that are of a certain size and created between two specific
> dates. If anyone can help I'd be grateful. Thanks in advance.


For example:
28> get-childitem|where {$_.lastwritetime -gt
[datetime]::now.date.adddays(-10) -and $_.lastwritetime -lt
[datetime]::now.date.adddays(-2) -and $_.length -gt 100}

'get-childitem -recurse' would go through all the sub-dirs also.

So the above gets files created in the last 10 days, up to 2 days ago.
Also, it will only get files larger than 100.

Marco
 

My Computer

$
#3
for the creation date just replace $_.lastwritetime with $_.CreationTime

--
$hay
http://scriptolog.blogspot.com



"Marco Shaw" <marcoDOTshaw_@_gmailDOTcom> wrote in message
news:u01VjryOHHA.2232@TK2MSFTNGP02.phx.gbl...
>> I am very new to using PowerShell. I would like it to search for files
>> on a drive that are of a certain size and created between two specific
>> dates. If anyone can help I'd be grateful. Thanks in advance.

>
> For example:
> 28> get-childitem|where {$_.lastwritetime -gt
> [datetime]::now.date.adddays(-10) -and $_.lastwritetime -lt
> [datetime]::now.date.adddays(-2) -and $_.length -gt 100}
>
> 'get-childitem -recurse' would go through all the sub-dirs also.
>
> So the above gets files created in the last 10 days, up to 2 days ago.
> Also, it will only get files larger than 100.
>
> Marco
>
 

My Computer

$
#4
You can replace the requested file size (e.g 100) with:

1kb
1mb
1gb

another example

get-childitem $env:userprofile"\desktop" -recurse| where {$_.length -gt 1mb}
| select name,length | sort length -desc | ft -autosize | more

Will drilldown the current user desktop for files greater than 1mb
and display the results (file name and file size) sorted by the file size,
bigger first.
a -filter can be added to reduce the number of returned objects.

Dont forget to double check your self when preforming distructive actions on
the files
use - whatif to test the operation and even -confirm to be on the safe side

--
$hay
http://scriptolog.blogspot.com



<acatejr@gmail.com> wrote in message
news:1169139729.858803.215170@38g2000cwa.googlegroups.com...
> Hi,
>
> I am very new to using PowerShell. I would like it to search for files
> on a drive that are of a certain size and created between two specific
> dates. If anyone can help I'd be grateful. Thanks in advance.
>
 

My Computer

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