Remove all PST from the Outlook Mailbox using VBScript

If you would like to remove all of the Personal Folders file .PSTs attached to the Outlook Mailbox profile then we can use RemoveStore Method.

‘Sample script to remove Personal Folders files (.pst) from the current MAPI profile or session

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

End Sub

email me