Skip to content

Delete old Blackberry Enterprise Server (BES) logs folder using vbscript

November 27, 2010

Deleting old BES logs can be simplified using this script. You can run this script manually on regular intervals or create /schedule a task on Blackberry server. To run this script you need to provide log folder path,  number of days older than logs to be deleted and whether to move or delete log file folders.

The method of running this script in command prompt…

cscript //NoLogo c:\scripts\deleteBESLogFolders.vbs  {BES logs folder path} {Mention: number of days} {mention: move|delete}

Examples:

This command will move logs older than 7 days from the folder “C:\Scripts\logs” where folder name value only contains numbers like “21112010”.

cscript //NoLogo c:\scripts\deleteBESLogFolders.vbs “C:\Scripts\logs” 7 move>> c:\scripts\BESLOg_Folder_Delete.log

This command will delete logs older than 7 days from the folder “C:\Scripts\logs” where folder name value only contains numbers like “21112010”.

cscript //NoLogo c:\scripts\deleteBESLogFolders.vbs “C:\Scripts\logs” 7 delete>> c:\scripts\BESLOg_Folder_Delete.log

——————————————————————————————————————————————————-

‘Copy and paste all the text below and create deleteBESlogFolders.vbs file.

‘Script: deleteBESlogFolders.vbs
‘Created By: Manish Girdhar
‘Date: 26 Nov 2010
‘Purpose: To delete/move folders from given path and all subfolders below this folder
‘ Usage: cscript DeleteBESlogFolders.vbs {DriveLetter:\FolderName} {#ofDays} {Delete or Move}
‘     or: cscript DeleteBESlogFolders.vbs {\\servername\FolderName} {#ofDays} {Delete or Move}
‘ Usage: cscript DeleteBESLogFolders.vbs c:\BES\log 3 d
‘    (deletes folders older than 3 days from the \BES\log file on drive C:)
‘Usage: cscript DeleteBESLogFolders.vbs c:\BES\log 3 m
‘  (moves folders older than 3 days from the \BES\log file on drive C: to C:\BES_Log_Backup)

Const BACKUP_FOLDER = “C:\BES_Log_Backup”   ‘Change path folder  to move log files
creatfold
Set ObjUsrInput = WScript.Arguments
FolderName =ObjUsrInput(0)
Days=ObjUsrInput(1)
Action=LCase(ObjUsrInput(2))
‘1
if action = “delete” or action = “move” or action = “d” or action = “m” then 
set fso = createobject(“scripting.filesystemobject”)
set folders = fso.getfolder(FolderName)
datetoday = now()
wscript.echo “”
wscript.echo “”
wscript.echo “”
wscript.echo “”
newdate = dateadd(“d”, Days*-1, datetoday)
wscript.echo “Current Date (Today):” & now()
wscript.echo “==================================================================”
wscript.echo “STARTING: Folders where date created is older than date :” & newdate &  ” Will be deleted / Moved.”
wscript.echo “<<________________________________________________>>”
wscript.echo “”
route folders
wscript.echo “”
wscript.echo “COMPLETED: All Folders created older than date :” & newdate &  ” are deleted / Moved.”
wscript.echo “<<________________________________________________>>”

‘=== Route Function Defined
sub route( byref folders)
set subfolders = folders.subfolders
‘==== For loop started
for each folder in subfolders
wscript.echo “” 
‘Check if Date is in limit
if folder.datecreated < newdate then
””check if folder name is numeric
if IsNumeric(folder.Name) = true then
‘==============================M
”if action is MOve
if action = “move” or action = “m” then
wscript.echo “__________________________________________________________________________”
wscript.echo “Move folder :” & folder.path
wscript.echo “”
folder.move BACKUP_FOLDER & “\” & folder.Name
‘track if error
if err <> 0 then
DisplayErrorInfo
else
wscript.echo “”
wscript.echo “Folder Moved :” & folder.path
wscript.echo “__________________________________________________________________________”
end if ‘ tracking error
end if
‘================================M
‘End if Action is Move
‘===================== D
‘if Action is delete
if action = “delete” or action = “d” then
dim foldpath
wscript.echo “__________________________________________________________________________”
foldpath = folder.path
wscript.echo “Deleting folder :” & foldpath
wscript.echo folder.path
folder.delete
if err <> 0 then
DisplayErrorInfo
else
wscript.echo “”
wscript.echo “Folder Deleted :” & foldpath
wscript.echo “__________________________________________________________________________”
end if
End if
‘End of action Delete
‘======================D
End if
end if
on error resume next
next 
‘====== for loop ended
set subfolders = nothing
set files = nothing
end sub
”’Function Route Ended
Else  ‘1

wscript.echo “Correct Action type not defined”

End if ‘1

Sub DisplayErrorInfo
    WScript.Echo “Error:      : ” & Err
    WScript.Echo “Error (hex) : &H” & Hex(Err)
    WScript.Echo “Source      : ” & Err.Source
    WScript.Echo “Description : ” & Err.Description
    Err.Clear
End Sub

sub creatfold
dim objFSO
set objFSO = createobject(“Scripting.FileSystemObject”)
if objFSO.FolderExists(BACKUP_FOLDER) then
else
objFSO.CreateFolder(BACKUP_FOLDER)
end if
End sub

Advertisements
4 Comments
  1. Tuleeka Nandy permalink

    Nice one Manish. This is a real help.With the growing number of posts, I believe this site will be a google for exch admins 🙂

  2. Rob permalink

    strPath = “D:\external\”

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objFolder = objFSO.GetFolder(strPath)
    Set colSubFolders = objFolder.SubFolders

    If colSubFolders.count > 0 Then
    For Each objSubFolder in colSubFolders
    If StrComp(objSubFolder.Name,”installer”,1) = 0 Or StrComp(objSubFolder.Name,”webserver”,1) = 0 Then
    x = 0
    Else
    x = 1
    End If
    If DateDiff(“d”,objSubFolder.DateCreated,Now) > 10 and x > 0 Then
    ‘objFSO.DeleteFolder objSubFolder ‘Uncomment to run
    WScript.Echo objSubFolder & ” will be deleted” ‘TEST
    End If
    x = 0
    Next
    End If

Trackbacks & Pingbacks

  1. Delete old Blackberry Enterprise Server (BES) logs folder using vbscript « Blackberry "Love what you do"
  2. Delete old Blackberry Enterprise Server (BES) logs folder using vbscript « Messaging & Collabration Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: