Further Automate Disk Clean-up by Scripting
April 29, 2009
For those of you who have a need to keep your server or workstation tidy, employing an automatic file deletion script may be right up your alley. Take for instance, your web logs, sql logs, or Windows temp files. All of these files can get really out of hand if not kept in check. You also may want to keep a shared folder on your server for “file swapping” with in your local LAN. If that is the case wouldn’t you like housekeeping to be done automatically? Letting your users know it is a temporary 14 or 7 day directory may even reduce your inneroffice exchange attachments or present itself as an alternative to failed large attachement size.
Below is a script that will allow you to specify the directory paths and the number of days from the date the script is run to retain data. If you want to delete all temporary files older than 7 days, your script will look like this: cscript DeleteOldFiles.vbs C:\windows\temp 7
Obviously the meat of the script is in the “DeleteOldFiles.vbs”, which is provided below.
If you have more than one directory you need to delete files in, simply duplicate your call and replace the directory path.
Now for the Script:
option explicit
Call DoTheJob()
WScript.Echo "--- end of script execution ---"
Sub DoTheJob
dim limitDate
dim formattedLimitDate
dim folder
dim strComputer
dim objWMIService
dim colFileList
dim objFile
dim nbFiles
dim totalFiles
dim nbErrors
dim result
dim nbDays
if WScript.Arguments.Count <> 2 then
WScript.Echo “usage : DeleteOldFiles.vbs
WScript.Echo “sample: DeleteOldFiles.vbs C:\Windows\temp 90″
Exit Sub
end if
folder = WScript.Arguments(0)
nbDays = WScript.Arguments(1)
‘calculate and format limit date
limitDate = DateAdd(”d”, -1 * nbDays , Date)
formattedLimitDate = DatePart(”yyyy”, limitDate)
if DatePart(”m”, limitDate) < 10 then
formattedLimitDate = formattedLimitDate & "0"
end if
formattedLimitDate = formattedLimitDate & DatePart("m", limitDate)
if DatePart("d", limitDate) < 10 then
formattedLimitDate = formattedLimitDate & "0"
end if
formattedLimitDate = formattedLimitDate & DatePart("d", limitDate)
'show what will be done
WScript.Echo "Will remove files from " & folder & " with a date older than " & formattedLimitDate & " (" & nbDays & " days ago)"
'Get the files and delete the old ones
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & folder & "'} Where " _
& "ResultClass = CIM_DataFile")
nbFiles = 0
totalFiles = 0
nbErrors = 0
For Each objFile In colFileList
totalFiles = totalFiles + 1
if objFile.CreationDate < formattedLimitDate then
result = objFile.Delete()
WScript.Echo objFile.Name & " - " & objFile.CreationDate & ". Delete Result: " & result
if result = 0 then
nbFiles = nbFiles + 1
else
nbErrors = nbErrors + 1
end if
end if
Next
'Show the result
Wscript.Echo "Total files in folder: " & totalFiles
WScript.Echo "Deleted files: " & nbFiles
WScript.echo "Errors: " & nbErrors
End Sub
Now the batch file that calls the clean up script:
cscript DeleteOldFiles.vbs C:\windows\temp 90
Here you will specify the path(s) you would like to clean up files and the age of the files to clean up.
Source cod provided by: http://blogs.msdn.com/benjguin/archive/2006/12/01/delete-old-files-script.aspx
Free up space on SBS system partition
April 23, 2009
Here is my standard list of what can be moved from the system partition of
an SBS server:
Moving Data Folders for Windows Small Business Server 2003
http://www.microsoft.com/technet/prodtechnol/sbs/2003/maintain/movedata.mspx
How to move Exchange databases and logs in Exchange Server 2003
http://support.microsoft.com/kb/821915
How to Move Small Business Server 2000 Company and Users Shared Folders
http://support.microsoft.com/default.aspx?scid=kb;en-us;329640
How to Move the Client Programs Folder to Another Location in Windows Small
Business Server 2003
http://support.microsoft.com/?scid=kb;en-us;830254
How to Move the Windows Default Paging File and Print Spooler to a Different
Hard Disk
http://support.microsoft.com/default.aspx/kb/314105
Also:
Look at where the ISA logs are kept
You can move the C:\windows\uninstall$ folders off your systemroot, but you
may want to keep them in case you have to move them back.
Remove any folders or files under the c:\documents and settings\user
name\local settings\temp folders.
If Monitoring is enabled it can create a file that could be large. Run
through the wizard again to flush out the gooey stuff..
Delete logs older than “date of your choice” from the system32 folder.
Likewise the logs and reports from the ISA folder.
Search for and delete old dmp files.
You can move the page file to another partition. The only downside is that
if you get a “blue screen” you will not get a full memory dump, and since
only MS can read them anyway, I don’t see that it matters much.
You may gain some usable space and increase system performance in Windows
Server 2003 by moving the printer spool files to a different drive than the
one that holds the operating system. Note that this should be a different
spindle, but a different partition will help the OS a bit also.
By default, Windows Server 2003 places the printer spool folder at
%systemroot%\System32\Spool\Printers. However, you can potentially increase
system performance by moving the printer spool files to a different drive
than the one that holds the operating system.
Computers frequently access system files, so moving the printer files to a
different location allows faster access to those files. The drive won’t have
to try to service requests simultaneously.
To change the location for the printer spooler files, follow these steps:
1. Go to Start | Printers And Faxes.
2. From the File menu, select Server Properties.
3. On the Advanced tab, enter the location where you would like to spool
print jobs. If the location doesn’t exist, this process will create it for
you. Make sure the new location has sufficient disk space to handle large
print jobs.
4. Stop and restart the printer spooler service, or reboot the server.
Enjoy



Recent Comments