Solved

VB script to detach PST in Outlook 2003

Posted on 2011-03-09
5
885 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
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…
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…

739 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