Link to home
Start Free TrialLog in
Avatar of williamfl
williamfl

asked on

Need a VBscript that can scan all the folders for Created and modified files by variable date.

I have a need to control a repository folder size with thousands of users using it. We need a VBscript that can scan all the folders for Created and modified file with in variable time periods. Such as last 24 hours. Add write out to file. Some teams are adding to many files and we just want to know who they are by reviewing there teams subfolder under the main teams repository folder.
Avatar of williamfl
williamfl

ASKER

We would like the output file to show the file sizes also so we can identify the team using the most space.
Avatar of RobSampson
Using Powershell would be the best option here.  There's a good article here:
http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/25/getting-directory-sizes-in-powershell.aspx

that should give you something close to what you need.

Rob.
gci  c:\folder -recurse | where {(!($_.PsIsContainer)) -and $_.CreationTime -gt (Get-Date).AddDays(-1)} | select Fullname, Length | export-csv report.csv -ntigci c:\folder -recurse  | {where $_.CreationTime - lt (get-Date).AddDays(-1)}

Open in new window

Bit messy on the end of your example there becraig, copy and paste problems by the looks of it. It might be a good idea to repost it.

I would add that:

> with thousands of users using it

You'll almost certainly hit the native path length limitation in .NET (260 characters). It's possible to work-around the limitation by creating temporary drive mappings or junctions, it's just quite deeply unpleasant (in my opinion).

Chris
ASKER CERTIFIED SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could also use Robocopy
Example:
robocopy sourcepath andvalidpath /L /minage:0 /maxage:1

Open in new window

Ok I'm awake now:

I've added the file owner/creator as well as the option for files modified in the past day as well as files created in the past day.

A quick overview of what the powershell script below does:
The first line gci -recurse checks the current folder and all child folders (You need to replace "gci  -recurse " with "gci \\share\folder -recurse")
The output is piped into a foreach loop and the output objects are created then piped to the export-csv command.


gci  -recurse | where {(!($_.PsIsContainer)) -and ($_.CreationTime -gt (Get-Date).AddDays(-1) -or $_.LastWriteTime  -gt (Get-Date).AddDays(-1))} | % {
$report = New-Object PSObject
$report | Add-Member -membertype NoteProperty -Name Owner ((Get-ACL $_.FullName).Owner)
$report | Add-Member -membertype NoteProperty -Name FileName -Value $_.Name
$report | Add-Member -membertype NoteProperty -Name ParentFolder -Value $_.DirectoryName
$report | Add-Member -membertype NoteProperty -Name Size -Value (("{0:N4}" -f ($_.length / 1MB) + "MB"))
}
$report | export-csv reports.csv -NoTypeInformation

Open in new window

Have you tested the script ?

Are there any issues to address ?