Solved

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

Posted on 2014-09-25
9
275 Views
Last Modified: 2014-10-25
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.
0
Comment
Question by:williamfl
9 Comments
 

Author Comment

by:williamfl
ID: 40344288
We would like the output file to show the file sizes also so we can identify the team using the most space.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40345455
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.
0
 
LVL 28

Expert Comment

by:becraig
ID: 40345464
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

0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 40345492
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
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 28

Accepted Solution

by:
becraig earned 500 total points
ID: 40345508
Very true Chris :~)

Methinks some sleep is needed:

Here is a cleaned up version:
gci  -recurse | where {(!($_.PsIsContainer)) -and $_.CreationTime -gt (Get-Date).AddDays(-1)} | % {
$report = New-Object PSObject
$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

0
 
LVL 45

Expert Comment

by:aikimark
ID: 40345849
You could also use Robocopy
Example:
robocopy sourcepath andvalidpath /L /minage:0 /maxage:1

Open in new window

0
 
LVL 28

Expert Comment

by:becraig
ID: 40346318
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

0
 
LVL 28

Expert Comment

by:becraig
ID: 40347682
Have you tested the script ?

Are there any issues to address ?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now