PowerShell

Delete Offline OST files from login users account using PowerShell.

 

Hi,

 

Yesterday I was surfing the TECHNET Script repository and see that one user is requested for a script which can delete offline email file {ost} from login users.

 

This seems simple to me and I wrote a 3line script which can accomplish this task.

 

Download the script from : http://gallery.technet.microsoft.com/scriptcenter/Delete-OST-from-User-App-22df1c88

1.  $OstPath = $Env:LocalAppData + “\Microsoft” + “\Outlook

2.  $ost = get-ChildItem$OstPath | where { $_.Extension -eq “.ost”} 

3.  $ost | remove-ItemWhatIf## remove -whatif to remove the files 

 

1.    In windows7 and with outlook 2010 installed the OST file are created in “C:\Users\USERNAME\AppData\Local\Microsoft\Outlook” folder. The $Env:LocalAppData windows environment variable contain the path of “C:\Users\aman.dhally\AppData\Local” and we added “\Microsoft” and “\Outlook” to make the complete path to the outlook folder.

2.    Secondly we are getting all files whose extension is equal .OST and saving the result in to the $ost variable

3.    Thirdly we are parsing the output of $ostto remove-Item to remove all files.

 

Screenshots:

Below is the path of my OST files.

14-02-2012 12-08-29 

See the default value of  $Env:LocalAppData data and the output of $OstPath when we added “Microsoft” and “Outlook” in to it.

14-02-2012 12-11-07

$ost = get-ChildItem$OstPath | where { $_.Extension -eq “.ost”}  , and just see the output of $ost you can see that is is showing the name of all OST which we have in out outlook folder.

14-02-2012 12-13-31

$ost | remove-ItemWhatIf

and this will remove the OST files 🙂

14-02-2012 12-15-16

Download the script from : http://gallery.technet.microsoft.com/scriptcenter/Delete-OST-from-User-App-22df1c88

Simple isn’t:)

 

Note: I tested this script on Windows7 with Outlook 2010 installed.

 

Thanks

Aman Dhally

3 thoughts on “Delete Offline OST files from login users account using PowerShell.

    1. Hi Mac,
      How to want to provide the usernames? because if we got all users profile name and use this with foreach then i think can be done

      $Ost = “C:\users” + “\username” + “\Appdata\Local\Outlook”

  1. ost recovery easily opens, recovers, moves your messages, contacts, notes, meetings, reminders, tasks and all other information. Software has easy to use, intuitive interface even for novices. Application starts under any Windows OS starting with Windows 98.

Comments are closed.