RE: Deleting 1 folder across multiple Mailboxes



I too am looking to delete about 30 folders that came over from a linux
migration and would love to find a way to script these folders away. There
are over 200 mailboxes that is a whole lot of click delete click delete.
Know what I am saying?

I found this script, but it seems to only work on Exchange 2000.

'================================================================================
' Copyright (c) 2005 Ted Crow, Information Technology Manager
' Tuttle Services, Inc. [ tedc@xxxxxxxxxxxxx / +1-419-228-6262 ]
'
' This file is provided free of charge and may be distributed freely so
' long as it is not modified in any way and this header remains completely
' intact.
'
'DISCLAIMER OF WARRANTY
' THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND WHETHER
' EXPRESSED OR IMPLIED. IN NO EVENT SHALL THE AUTHOR BE HELD LIABLE FOR ANY
' DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF
BUSINESS
' PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS OR PERSONAL INFORMATION, OR
' ANY OTHER LOSS ARISING FROM THE USE OR INABILITY TO USE THE SOFTWARE.
'================================================================================

Option Explicit

Dim objCommand, objConnection, strBase, strFilter, strAttributes
Dim objSysInfo, strQuery, objRecordset, strName, strFolderName
Dim strServerName, strDomainDNSName, res, ShowConfirmation

strServerName = "mail server name"
strFolderName = "Spam"
strBase = "<LDAP://dc=mydomain,dc=com>"
ShowConfirmation = 1

'================================================================================
' YOU SHOULD NOT NEED TO EDIT ANYTHING BELOW THIS LINE!
'================================================================================

'Set objSysInfo = CreateObject("ADSystemInfo")
'strDomainDNSName = objSysInfo.DomainDNSName

Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

strFilter = "(&(&(& (mailnickname=*) (|
(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*))) ))))"
strAttributes = "sAMAccountName,cn"

strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
objCommand.Properties("Sort On") = "sAMAccountName"

Set objRecordSet = objCommand.Execute

Do Until objRecordSet.EOF

strName = objRecordSet.Fields("sAMAccountName").Value

res = DeleteFolderFromMailbox ( strServerName, strName, strFolderName )

objRecordSet.MoveNext

Loop

objConnection.Close

'================================================================================
' THE CORE OF THIS SCRIPT
'================================================================================

Function DeleteFolderFromMailbox(strServerName,strMailboxName,strFolderName)

On Error Resume Next

Dim objRecord, strObjectUrl, ConfirmDelete

ConfirmDelete = 7 'vbNo

Set objRecord = CreateObject("ADODB.Record")

' Specify the URL to the item to be deleted
strObjectUrl = "http://"; & strServerName & "/exchange/" & strMailboxName &
"/" & strFolderName

'MsgBox "strObjectUrl : " & strObjectUrl

' Open the record
objRecord.Open strObjectUrl,,3 ' adModeReadWrite

If (Err.Number = 0) Then
If (ShowConfirmation = 1) Then
ConfirmDelete = MsgBox("Delete Folder '" & strFolderName & "' from
mailbox : " & strMailboxName & " (" & strServerName & ")",4,"Delete Folder")
Else
'MsgBox "DAV:href : " & objRecord.Fields("DAV:href")
ConfirmDelete = 6 ' vbYes
End If

' Delete the folder record
If (ConfirmDelete = 6) Then
objRecord.DeleteRecord
End If

End If

' Close the record and clean up
objRecord.Close
Set objRecord = Nothing

End Function

"Griff" wrote:

> We created a duplicate junk mail folder and want to delete it across multiple
> mailboxes. Is there a utility that will do this or do we need to open each
> mailbox individually? We have 1200 mailboxes.
> Thank you
.



Relevant Pages

  • Re: Exchange2003 Schema Question
    ... Yes script it. ... If I want to add few more folders on the same level as the inbox under all ... the mailboxes. ...
    (microsoft.public.exchange.admin)
  • Re: CLean out all users Temp Dir Folder
    ... I've built the script you need with ScriptAhead a tool we have just ... ' Get Folders that match the following criteria: ... Sub AppendCollectionToArray ... GetSubFolders strFolderName ...
    (microsoft.public.windows.server.scripting)
  • Problem Identified
    ... Outlook cannot tolerat a missing Offline Address Folder in the public ... It prevents users from navigating between the Mailbox folders. ... with mailboxes, but OWA works fine for everyone. ... server, then back to the original hardware using the Jeff Middleton ...
    (microsoft.public.windows.server.sbs)
  • Re: Need help for a new scripter
    ... been tasked with comming up with a script that will allow me to move ... folders from the profile into it. ... Dim sUserProfile, sBUPath ... sPath & "\quicklaunch", OverWriteFiles ...
    (microsoft.public.scripting.vbscript)
  • Re: Administrative access to users sub folders?
    ... user account for him and adding him to the appropriate group got him to be ... When you say that he would have to "add them as additional mailboxes to open ... THe end result is that we he opens ... was not able to see the 40 or so folders that I created within my outlook ...
    (microsoft.public.exchange2000.information.store)