Solved

VB script to detach PST in Outlook 2003

Posted on 2011-03-09
5
862 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

Suggested Solutions

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…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now