Solved

VB script to detach PST in Outlook 2003

Posted on 2011-03-09
5
870 Views
Last Modified: 2012-05-11
I have over 300 mailboxes that are on an Exchange 2003 server, that I need to move to Exch2007.  Before I do this, I need to drop the active PST from that user's Outlook session.  I see a VB script to attach one, but I need a script that detaches the active PST for Outlook 2003.  I have one for Outlook 2007, but it won't run on 2003 - hence need a separate VB script to do this.
0
Comment
Question by:Monterio
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:Monterio
ID: 35087936
I intend to run this script on the users machine directly, so I don't need to do this to 300 machines or something crazy like that - just one machine/mailbox at a time.
0
 
LVL 11

Expert Comment

by:TheGorby
ID: 35088212
This looks like it might get the job done:

http://blogs.msdn.com/b/brijs/archive/2009/05/06/remove-all-pst-from-the-outlook-mailbox-using-vbscript.aspx

I'm not sure which, if not all, versions of Outlook this will work on.
0
 
LVL 1

Author Comment

by:Monterio
ID: 35095740
Hi!

Thanks for the suggestion.  The thing I see in this article is that some of the code is cut off on a couple of lines.  I'm no scripter, but I do remember that conditional statements have beginning and ending elements.  There's an incomplete If/And/Then statement...the code's cut-off so I don't know what the rest of that statement is supposed to be.  I know enough that the script will fail as it currently is.  Can you complete the rest of that script so that I have everything for it to run successfully?  I cannot test it as it is unfortunately.
0
 
LVL 11

Accepted Solution

by:
TheGorby earned 250 total points
ID: 35098009
It certainly is cut off, sorry for not catching that before. I'm not yet at a place where I can test this but I think this should work:
'Sample script to remove Personal Folders files (.pst) from the current MAPI profile or session
RemoveAllPST 

Sub RemoveAllPST()
Dim objOL 'As New Outlook.Application
Dim objFolders 'As Outlook.MAPIFolders
Dim objFolder 'As Outlook.MAPIFolder
Dim i 'As IntergerDim strPrompt 'As String 

Set objOL = CreateObject("Outlook.Application")
Set objFolders = objOL.Session.Folders
For i = objFolders.Count To 1 Step -1
	On Error Resume Next
    Set objFolder = objFolders.Item(i)
	'Prompt the user for confirmation
    If (InStr(1, objFolder.Name, "Mailbox") = 0) And (InStr(1, objFolder.Name, "Public Folders") = 0) Then
		strPrompt = ""
		strPrompt = "Are you sure you want to remove " & objFolder.Name
		If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
			objOL.Session.RemoveStore objFolder
		End If
    End If
Next
End Sub

Open in new window

0
 
LVL 11

Expert Comment

by:TheGorby
ID: 35099744
I just noticed an error I made in copying/pasting the script on line 8... but hey if it's working for you then no big deal! Just in case though, here it is corrected:
'Sample script to remove Personal Folders files (.pst) from the current MAPI profile or session  
RemoveAllPST   
  
Sub RemoveAllPST()  
Dim objOL 'As New Outlook.Application  
Dim objFolders 'As Outlook.MAPIFolders  
Dim objFolder 'As Outlook.MAPIFolder  
Dim i 'As Interger
Dim strPrompt 'As String   
  
Set objOL = CreateObject("Outlook.Application")  
Set objFolders = objOL.Session.Folders  
For i = objFolders.Count To 1 Step -1  
    On Error Resume Next  
    Set objFolder = objFolders.Item(i)  
    'Prompt the user for confirmation  
    If (InStr(1, objFolder.Name, "Mailbox") = 0) And (InStr(1, objFolder.Name, "Public Folders") = 0) Then  
        strPrompt = ""  
        strPrompt = "Are you sure you want to remove " & objFolder.Name  
        If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then  
            objOL.Session.RemoveStore objFolder  
        End If  
    End If  
Next  
End Sub

Open in new window

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

777 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