Need Script to Search for OST files on Local Drive

Posted on 2010-01-11
Medium Priority
Last Modified: 2012-05-08

I need help with a script that completes 3 tasks:

1. Stops Outlook application so OST is not locked.

2.  Searches for each .OST file within the C:\Documents and Settings\<username>\Local Settings\Application Data\Microsoft\Outlook directory and

3. Renames each file in said directory with another extension like .backup.  

Any help is appreciated. Thanks.
Question by:SugaBaby
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

Author Comment

ID: 26290527
I came up with this. Instead I seach using WMI, taking away directory restriction.

'On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile Where Extension = 'ost'")

If colFiles.Count = 0 Then
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")

For Each objFile in colFiles
    strNewName = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension & ".BACKUP"
    errResult = objFile.Rename(strNewName)

LVL 20

Accepted Solution

ltlbearand3 earned 2000 total points
ID: 26423729
WMI is what you want to use here to accomplish your tasks.  I modified SugaBaby's code to include stopping outlook like you requested.

option explicit

Dim strComputer, objWMIService, objProcess, colProcess
Dim colFiles, objFile

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

' Stopping Outlook
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'outlook.exe'")
For Each objProcess in colProcess

' Look for all ost files on machine
Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile Where Extension = 'ost'")

If colFiles.Count = 0 Then
	wscript.echo "No .OST Files were found."
End If

' Rename the Files to .BACKUP
For Each objFile in colFiles
    strNewName = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension & ".BACKUP"
    errResult = objFile.Rename(strNewName)

Wscript.Echo "Re-naming is complete"

Open in new window


Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

764 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