Tech Line

Poor Man’s SRM

Here’s a script that can locate unauthorized files in a user’s home folder.

Chris, I have been trying to enforce disk quotas on one of my file servers. I like using the tool diskuse.exe from the Windows Server 2003 Resource Kit to list users at or near their quota limit. When I see users nearing their quota, I would like to check their home folders for unauthorized content, such as MP3 files. I know that there are some SRM tools that can do this, but it's not in my budget. Is there something else you can recommend?
— Chad

Tech Help—Just An
E-Mail Away

Got a Windows, Exchange or virtualization question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to the editors at; the best questions get answered in this column and garner the questioner with a nifty baseball-style cap.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message, but submit the requested information for verification purposes.)

Chad, that’s a very good question. I have not seen any free storage resource management tools, since most commercial tools are quite powerful and require extensive development. However, that’s not to say that you can’t do some simple file audits for any user.

For example, the good ‘ol dir command can identify any file by type within a particular folder tree. Suppose you want to list all of the MP3 files within the "home" folder on your server. To do this, you could run the following command (assuming the home folder is on the E drive):

dir e:\home\*.mp3 /s

Of course, you probably want to redirect the output to a text file in order to view the complete command output. So in that case, you'd run it this way:

dir e:\home\*.mp3 /s > storagehogs.txt

Now, you can easily see who's using your file server to back up their MP3 collections. Since I’m assuming that each subfolder of your "home" folder will be named after each user in your domain, identifying the abusers will be pretty easy.

Here’s a simple batch file that you could use to look for multiple file types and store the results in a text file:

@echo off
:: Set Variables
set TargetFolder=E:\Home
set ReportFolder=C:\UsageReports
set Today=%Date:~4,2%-%Date:~7,2%-%Date:~10,4%

:: Check for ReportFolder and create it if necessary
if not exist %ReportFolder% md %ReportFolder%

:: Query and report on unauthorized file types
dir %TargetFolder%\*.mp3 /s >> %ReportFolder%\%Today%.txt
dir %TargetFolder%\*.wma /s >> %ReportFolder%\%Today%.txt
dir %TargetFolder%\*.wmv /s >> %ReportFolder%\%Today%.txt
dir %TargetFolder%\*.avi /s >> %ReportFolder%\%Today%.txt

If saved as a batch file, you could use the task scheduler to run this once a week, for example. Each saved report will simply be named after the date on which the report was run (example: 08-15-2006.txt). This is probably the easiest way to get the type of reporting you are looking for.

If VBscripting is more your game, here’s a VBscript that would also do the same job.

' Set variables
strToday= Year(Date)&"-"& Month(Date)&"-"&Day(Date)
strOutput = ReportFolder& "\" & strToday &".txt"

'create output folder if needed
Set objFolder = CreateObject("Scripting.FileSystemObject")
If not objFolder.FolderExists(ReportFolder) Then
   Set objFolder = objFolder.CreateFolder(ReportFolder)
End If

'Write unauthorized files to output folder
Set objShell = CreateObject("WScript.Shell")
'mp3 files
strCommand = "%comspec% /c dir "&_
  TargetFolder &"\*.mp3 /s > "& strOutput,2,true
'wma files
strCommand = "%comspec% /c dir "&_
   TargetFolder &"\*.wma /s >> "& strOutput,2,True
'wmv files
strCommand = "%comspec% /c dir "&_
  TargetFolder &"\*.wmv /s >> "& strOutput,2,True
'avi files
strCommand = "%comspec% /c dir "&_
  TargetFolder &"\*.avi /s >> "& strOutput,2,true

While there’s no doubt either of these scripts will not replace a tool like Veritas CommandCentral Storage, they can solve your problem of identifying wasted storage. Now, how you decide to embarrass the violators of your file server storage policy is up to you. I’m sure your fellow readers could give you a few pointers on that. I think an America’s Most Wanted-style filmed takedown would be the way to go, but I don’t think I would try that if my job depended on it.

On another note, I'd like to hear from all of you on your favorite free troubleshooting tools. I will provide information on all of the tools I receive in a future column. The reader that sends me the most quality tool resources will get a signed copy of my book Troubleshooting Microsoft Technologies.

About the Author

Chris Wolf is a Microsoft MVP for Windows --Virtual Machine and is a MCSE, MCT, and CCNA. He's a Senior Analyst for Burton Group who specializes in the areas of virtualization solutions, high availability, storage and enterprise management. Chris is the author of Virtualization: From the Desktop to the Enterprise (Apress), Troubleshooting Microsoft Technologies (Addison Wesley), and a contributor to the Windows Server 2003 Deployment Kit (Microsoft Press).learningstore-20/">Troubleshooting Microsoft Technologies (Addison Wesley) and a contributor to the Windows Server 2003 Deployment Kit (Microsoft Press).

comments powered by Disqus

SharePoint Watch

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.