Datamining PST Files using Microsoft.Office.Interop.Outlook

I was wondering how to datamine a pst file beyond it's primary folders to see if an empty folder has content in a subfolder and add it to an existing psobject?
Cheers,
B.
$results = New-Object System.Collections.ArrayList # Empty Array
$null = Add-type -assembly Microsoft.Office.Interop.Outlook
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace('MAPI')
$pstpath = "d:\sample.pst"
$namespace.AddStore($pstpath)
$PST = $namespace.Stores | ? {$_.FilePath -eq $pstpath}
$PSTRoot = $PST.GetRootFolder()
$PSTName = $PST.Displayname
Foreach ($folders in $PSTRoot.Folders) {
$x = $folders.Name
$y = $folders.FolderPath
$z = $folders.Items.Count
$Object = New-Object PSObject
$Object | Add-Member -Name 'Name' -MemberType Noteproperty -Value $x
$Object | Add-Member -Name 'Path' -MemberType Noteproperty -Value $y
$Object | Add-Member -Name 'Items' -MemberType Noteproperty -Value $z
$results += $object
$results | Format-Table 'Name','Path','Items' -Wrap -AutoSize | Out-Default
$results = $NULL

Hi B,
If you want to test the access of the .pst file, please refer to the function below:
function Test-PSTFile {
param(
[Parameter(Position=1, ValueFromPipeline=$true, Mandatory=$true)]
$FilePath,
[Parameter(Position=2, Mandatory=$false)]
$ErrorLog
process {
#Create an instance of Outlook
$null = Add-type -assembly Microsoft.Office.Interop.Outlook
$olFolders = 'Microsoft.Office.Interop.Outlook.olDefaultFolders' -as [type]
$outlook = new-object -comobject outlook.application
#Open the MAPI profile
$namespace = $outlook.GetNameSpace('MAPI')
try {
#Try to add the PST file to the profile
$namespace.AddStore($FilePath)
#Try to read the root folder name
$PST = $namespace.Stores | ? {$_.FilePath -eq $FilePath}
$PSTRoot = $PST.GetRootFolder()
if($PSTRoot) {
New-Object PSObject -Property @{
FileName = $FilePath
Valid = $True
#Disconnect the PST
$PSTFolder = $namespace.Folders.Item($PSTRoot.Name)
$namespace.GetType().InvokeMember('RemoveStore',[System.Reflection.BindingFlags]::InvokeMethod,$null,$namespace,($PSTFolder))
catch {
#If logging is on, save the error to the log
if($ErrorLog) {
Add-Content -Path $ErrorLog -Value ("Ran into a problem with {0} at {1}. The error was {2}" -f $FilePath, (Get-Date).ToString(),$_.Exception.Message)
#Output a failure record
New-Object PSObject -Property @{
FileName = $FilePath
Valid = $False
Refer to:
How to Test Outlook (PST) Personal Folder File Access with PowerShell
If there is anything else regarding this issue, please feel free to post back.
Best Regards,
Anna Wang

Similar Messages

  • On cleanuing up COM object when using Microsoft.Office.Interop.Excel

    When using Microsoft.Office.Interop.Excel the COM objects that are created by the code must be released using System.Runtime.InteropServices.Marshal.ReleaseComObject().
    Most of the time it's pretty clear when a new COM object is created such as:
    Excel._Application excelApp = null;
    Excel._Workbook wb = null;
    Excel._Worksheet ws = null;
    Excel.Range newRange = null;
    try
    // four COM objects are created below
    excelApp = new Excel.Application();
    wb = excelApp.Workbooks.Add();
    ws = (Excel.Worksheet)wb.Worksheets.Add();
    newRange = (Excel.Range)ws.Range["A1","A30"];
    // do these line of cod create new COM object?
    newRange.Font.Bold = true;
    newRange.Borders.Color = borderColor;
    finally
    if (excelApp != null) Marshal.ReleaseComObject(excelApp)
    if (wb != null) Marshal.ReleaseComObject(wb)
    if (ws != null) Marshal.ReleaseComObject(ws)
    if (newRange != null) Marshal.ReleaseComObject(newRange)
    In the above code I create four COM objects in the first part that need to be released when I'm finished with them. But it's not clear if the other two lines of code create a new COM object or not.  If they do then my code needs to look more
    like this:
    Excel._Application excelApp = null;
    Excel._Workbook wb = null;
    Excel._Worksheet ws = null;
    Excel.Range newRange = null;
    Excel.Font fnt = null;
    Excel.Borders bds = null;
    try
    // four COM objects are created below
    excelApp = new Excel.Application();
    wb = excelApp.Workbooks.Add();
    ws = (Excel.Worksheet)wb.Worksheets.Add();
    newRange = (Excel.Range)ws.Range["A1","A30"];
    // do these line of cod create new COM object?
    fnt = newRange.Font
    fnt.Bold = true;
    bds = new newRange.Borders;
    bds.Color = borderColor;
    finally
    if (excelApp != null) Marshal.ReleaseComObject(excelApp)
    if (wb != null) Marshal.ReleaseComObject(wb)
    if (ws != null) Marshal.ReleaseComObject(ws)
    if (newRange != null) Marshal.ReleaseComObject(newRange)
    if (fnt != null) Marshal.ReleaseComObject(fnt)
    if (bds != null) Marshal.ReleaseComObject(bds)
    How can I tell if getting a property creates a new COM object or not?

    Thank you for your replay but I do understand that the font object is a COM object.  What I'm trying to figure out is if a NEW object is created each time I access the font member of a Range object and if I need to call
    Marshal.ReleaseComObject on the font object after using it.
    Most member object of an object are a single instance and each time you access the member you simply get the pointer to that instance. For example:
    using(DataTable dt = new DataTable("Some Table Name"))
    PropertyCollection ep1 = dt.ExtendedProperties;
    PropertyCollection ep2 = dt.ExtendedProperties;
    if (Object.ReferenceEquals(ep1,ep2)) Console.WriteLine("They are the same object");
    else Console.WriteLine("They are different objects");
    The output will be: They are the same object
    On the other hand this:
    Excel._Application excelApp = new Excel.Application();
    Excel._Workbook wb = excelApp.Workbooks.Add();
    Excel._Worksheet ws = (Excel.Worksheet)wb.Worksheets.Add();
    Excel.Range newRange = (Excel.Range)ws.Range["A1","A30"];
    // do these lines of code create new COM object?
    Excel.Font ef1 = newRange.Font;
    Excel.Font ef2 = newRange.Font;
    if (Object.ReferenceEquals(ef1,ef2)) Consloe.WriteLine("They are the same object");
    else Consloe.WriteLine("They are different objects");
    The output will be: They are different objects
    It looks like each time I access the font member I get a new object.  I suspect that is not the case and what I am getting is two pointers to the same object and the reference counter is incremented by one.
    So really the question is what happens to the font member object of the Range object when the range object is released.  I assume the font member will be released along with the Range object ever if the font object has a reference count greater then
    0.
    If I am correct in my assumption then I can access the font member object as much as I need to without worrying about releasing it.
    I have been reading a lot about working with COM and the need to use Marshal.ReleaseComObject and there does seem to be a lot of disagreement and even confusion on the
    mater about when and if COM objects need to be explicitly released.

  • Interface not registered (Exception from HRESULT: 0x80040155) when calling Microsoft.Office.Interop.Outlook.MAPIFolder.get_Folders()

    Hi All,
    I have an Outlook COM addin written in C#. It is working without any issues on most client machines, but since of late it has started giving the above Exception for some clients running Outlook 2010.
    I understand that the issue is that the particular interface is not registered properly on those machines. I would like to know what in dll that interface is located and what could cause it to be missing? Can it be a component that had been deselected during
    the installation of Outlook? If so, what is that component? Or should the dll be manually registered (using REGSVR32)? Or will running a simple repair on Outlook work?
    Thanks!!

    Hello Thimila,
    What code do you use exactly?
    Try to run the problematic piece of code from VBA as a macro. Do you get the same error message? If so, you need to repair Outlook, it looks like windows registry entries were corrupted. 
    If you don't get such error in VBA it indicates that you didn't install/copy one of the required prerequisites to the end user PC (interop libraries, .net runtime and etc.). Make sure that all the required prerequisites are installed correctly. See Deploying
    an Office Solution for more information.

  • How to add text vertically into a Word margin with C# (using namespace: Microsoft.Office.Interop.Word)

    I need to add text vertically in a word document outside the margins.  How can I do this with Microsoft.Office.Interop.Word and C#?
    Leonard Swarczinski Software Developer Postal Center International

    Hi Leonard,
    According to your description, do you want to add text vertically into Page Header/Footer? I wrote a sample  for you.
    using Microsoft.Office.Core;
    using Microsoft.Office.Interop.Word;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace AddTextToWord
    class Program
    static void Main(string[] args)
    CreateNewDocument();
    Console.ReadLine();
    private static void CreateNewDocument()
    Object oMissing = System.Reflection.Missing.Value;
    Microsoft.Office.Interop.Word.Application oWord;
    Microsoft.Office.Interop.Word.Document oDoc;
    oWord = new Microsoft.Office.Interop.Word.Application();
    oWord.Visible = true;
    oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    String HeaderText = "Hello everyone!";
    WdParagraphAlignment wdAlign = WdParagraphAlignment.wdAlignParagraphCenter;
    AddHeader1(oWord, HeaderText, wdAlign);
    private static void AddHeader1(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign)
    Object oMissing = System.Reflection.Missing.Value;
    WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
    WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
    Microsoft.Office.Interop.Word.Shape textBox = WordApp.ActiveDocument.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationVertical, 150, 10, 40, 40);
    textBox.TextFrame.TextRange.Text = HeaderText;
    WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;
    If I misunderstood or anything wrong, please let me know and you can get more information from below articles.
    Office development in Visual Studio
    http://msdn.microsoft.com/en-us/office/hh133430.aspx
    Abhout: AddTextbox Method
    http://msdn.microsoft.com/en-us/library/office/aa171543(v=office.11).aspx
    How to: Programmatically Insert Text into Word Documents
    http://msdn.microsoft.com/en-us/library/vstudio/6b9478cs.aspx

  • I use Microsoft Office Professional Plus 2010, when clicking a link in Outlook I always get a General Failure box stating 'The system cannot find the file specified' yet it still goes to the specified page. Any ideas on how to resolve this

    I use Microsoft Office Professional Plus 2010, when clicking a link in Outlook I always get a box stating
    General Failure. The URL was "http:// etc etc".The system cannot find the file specified.
    Yet it still goes to the specified page. Any ideas on how to resolve this

    I am having the exact same problem with Windows 7 Professional. Out of the blue, this issue just started a few months ago when running my monthly Windows Backup where I have used a USB drive for the last 3 years, and never ever had this issue before. Most
    of the solutions listed on the Microsoft websites and answers deal with
    "Restore" functions, not the
    "Backup" itself. I have 3 folders being skipped during the backup.
    So I went and changed the Backup from "let Microsoft choose files, directories, etc" to "Let me choose". I included the files and folders that were being skipped, and ran the "Backup" again, and got the same error message,
    but the files that were skipped the first time were "Backed up" finally. This issue is somehow related to my "Libraries"?
    The 3 backup problems are:
    Backup encountered a problem while backing up file C:\Windows\System32\config\systemprofile\My Audio Books\Audio Book Recordings. Error:(The system cannot find the path specified. (0x80070003))
    Backup encountered a problem while backing up file C:\Windows\System32\config\systemprofile\My Audio Books\Audio Book CD Label-Cover Art. Error:(The system cannot find the path specified. (0x80070003))
    Backup encountered a problem while backing up file C:\Windows\System32\config\systemprofile\My Audio Books\Audio Book MP3 Tag Art. Error:(The system cannot find the path specified. (0x80070003))
    Did a "checkdisk" - no problems. Ran a program to fix registry - no problems. All updates up to date. I guess I could eliminate these folders from the Backup folders in the
    Library, and just choose them under the "Users" locations, and be done with it. But I really want to understand this, and fix it. This is within Windows 7 and may be related to Windows Media Player or
    some recent Windows update.  Thanks.

  • How to view pst file without Microsoft Outlook?

    How to view pst file without Microsoft Outlook? Please suggest viewer for content of corrupted PST files.

    Hi,
    If the .pst file is corrupted, I suggest you run Scanpst.exe to repair it:
    http://support.microsoft.com/kb/272227
    If you need to view .pst file without Outlook, we may use some 3rd-party tools, there are a lot on Internet.
    Regards,
    Melon Chen
    TechNet Community Support

  • File or assembly name microsoft.office.interop.excel or one of its dependen

    Hi Team,
    When i click on the manage dimension members for a dimension i am getting the following error,
    "file or assembly name microsoft.office.interop.excel or one of its dependencies was not found"
    How i can resolve this?
    Regards,
    Raj,

    Hi Raj,
    What did you do exactly to resolve this issue? Are you no longer using Office 2007 or did you reinstall it? What are the specific steps you took?
    I recently upgraded from SP02 to SP07 and now have the same problem. It was working fine prior to the upgrade.
    Thanks,
    Rob
    Edited by: Rob Delong on Feb 19, 2010 3:42 AM

  • Error 1310. Error writing to file: Policy.12.0.Microsoft.Office.Interop.Access.dll AHHHHHH!!!

    I'm trying to install Office 2010 Professional Plus on Windows 7 Ultimate
    I keep getting this error and I'm at witts end
    Error 1310. Error writing to file: Policy.12.0.Microsoft.Office.Interop.Access.dll.
    Verify that you have access to that directory
    I have completely uninstalled Office 2007, ran CCLeaner, Windows Install Cleanup, followed the idea's on the forums
    http://social.technet.microsoft.com/Forums/en-US/office2010/thread/4e8beb60-ac2b-4fc5-b510-628b65d7cc67
    WTH? I get the same error no matter what I do, Can anyone PLEASE help?

    Hi
    Thank you for using
    Microsoft Office for IT Professionals Forums.
    Follow these methods one by one test this issue:
    1.      
    Complete uninstall previous version of office: 
    http://support.microsoft.com/kb/290301
    2.      
    troubleshoot a problem by performing a clean boot in Windows 7
    http://support.microsoft.com/kb/929135
    3.      
    Test with a new user account
    Ÿ  
    Create a user account
    Ÿ  
    Fix a corrupted user profile
    Please take your time to try the suggestions and let me know the results at your earliest convenience. If anything is unclear or if there is anything I can do for
    you, please feel free to let me know.
    Best regards
    William Zhou
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Over the last few wks, i have lost several important file. Even the support team has not been able to recover them. Pls offer advice. I use microsoft office on my macbook pro, which is less than a year old.ce.

    Over the last few wks, i have lost several important file. Even the support team has not been able to recover them. Pls offer advice. I use microsoft office on my macbook pro, which is less than a year old.

    pklfromarlington wrote:
    Bob, Hate to steal your thunder but am hooked to an external hard drive using Time Machine and er information is where it shoudl be. Yes, I have combed the files, used Finder and any other tools I know.
    You did not steal my thunder. You asked for advice, I provided advice. I assumed that since you nor the "support team" could find your files that you did not have any backup. You should have told us you do regular backups. We have no way to know otherwise unless you tell us.

  • Hello, I cannot show my video files on microsoft office program with  macair book 11 inc notebook while using projector

    I cannot show my video files on microsoft office program with  macair book 11 inc notebook while using projector

    When you next have the problem, note the exact time: hour, minute, second.
    If you have more than one user account, these instructions must be carried out as an administrator.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left. If you don't see that menu, select
    View ▹ Show Log List
    from the menu bar.
    Scroll back in the log to the time you noted above. Select any messages timestamped from then until the end of the episode, or until they start to repeat, whichever comes first. Copy the messages to the Clipboard by pressing the key combination command-C. Paste into a reply to this message (command-V).
    When posting a log extract, be selective. In most cases, a few dozen lines are more than enough.
    Please do not indiscriminately dump thousands of lines from the log into this discussion.
    Important: Some private information, such as your name, may appear in the log. Anonymize before posting.

  • I have a MacBook Pro (purchased in 2011) with OS X Lion 10.7.4.  I'm using Microsoft Office 2011 and cannot open older PowerPoint Files (non .pptx). It will always open the same .pptx file and then the machine hangs up and just keeps spinning.

    I have a MacBook Pro (purchased in 2011) with OS X Lion 10.7.4.  I'm using Microsoft Office 2011 and cannot open older PowerPoint Files (non .pptx). It will always open the same .pptx file and then the machine hangs up and just keeps spinning.

    Thank you - that all makes sense. It is, indeed, exactly what I did when I upgraded.
    I'm also writing this on the machine that crashed a few minutes ago (I posted the crash in another thread). I got back with a 'safe boot' - as I have done a few times before.
    I've also de-installed little snitch (and then done a safe-boot & then re-boot ) since that seemed involved. I de-installed Adobe flash, since that seemed to be a problem - I then re-installed the later, apparently fixed, flash. The most recent crashes don't seeme to have a problem with flash any more.
    I've posted the various ( generally different ) crashes. I also posted a summary of the similar lines that turn up in most of the crashes.
    Unfortuantely, I'm actually trying to use the machine to meet some urgent deadlines and all this is not making it at all easy.
    I had had great hopes for 10.7.2 - I thought that the crashes must be pretty common, so would have a common aetiology. There do seem to have been some fundamental changes to the file sytem and to the video interface (that seems to cause problems to brand new iMacs as well as to my 2009 iMac).

  • How to keep a backup of olm data file of microsoft office in mac

    Hello
    I am a new user of mac and need help in keeping a backup file of olm file of microsoft office Outlook.
    I bought my macbook pro 3 days back and imported my old mails from .pst file of my windows laptop and now need to keep the backup of olm file of outlook for future use,
    Can anybody please help me doing this.
    Thanks in Advance

    Hi deepak_bhatia,
    Thanks for using Apple Support Communities. Based on what you stated, it sounds like you want to backup your data. I would recommend that you read this article, it may be able to help the issue.
    Mac Basics: Time Machine backs up your Mac - Apple Support
    Cheers,
    Mario

  • Export a mail as PST file using EWS API

    Hi,
    I need to export the Exchange mails to PST file without installing the outlook. To acheive this i am choosing the EWS API. but i dont know how to do that. So, now i have a two questions, the first one, is it possible to create the pst file using EWS API?.
    If yes, how to create a pst file using EWS, if any one posted the sample code here, it is very helpful for me.
    Thanks,
    RamMohan

    EWS is not going to help you do what your trying to do, EWS is an Exchange API so you need to have an Exchange 2007 server or greater with the MailStore mounted to even use it to access the Mailbox . EWS also doesn't support exporting email to a PST because
    the PST file is an Office file format so in the case where you do manage to mount the database on Exchange then use Adam's suggestion or just connect via Outlook and export the Mailbox.
    >> I am parsing the mails from the exchange EDB files
     With what ? reading the contents of an EDB file directly is not supported although there are a few third party apps that can do it and if your using one of those apps then all of them I've seen support the export to PST (unless your using a Trial licence). 
    The correct method of recovering data from an EDB file would be to use a Recovery Database
    https://technet.microsoft.com/en-us/library/dd876954(v=exchg.150).aspx even if you don't have access to the environment you should be able to setup a temp environment using Virtual machines and recover it that way.
    Cheers
    Glen

  • How can i use microsoft office on the mAC - what app do i purchase? help?!!

    how can i use microsoft office on the mAC - what app do i purchase? help?!!

    What aspect of Microsoft Office? Office is a suite of programs... Word, Excel, Powerpoint, etc.
    You've got several potential options. Libre Office and Open Office (both googleable) are 'open source,' free, downloadable programmes that will open most MS Office programmes and perform many of the functions of MS Office. Might be an idea to have a look round for reviews (etc) first, to see if they sound like they'll match your needs.
    If you're keen to use the App Store, there's Apple's own suite of programmes: Pages, Numbers and Keynote. They're a word processor, spreadsheet programme, and presentation-type programme with similar functions to Word, Excel and Powerpoint respectively. They're pretty good for most functions, and are better integrated with Macs than MS programmes. They're excellent programmes for what they do, and relatively cheap (about £14 each?).
    But if you're heavily reliant on MS, want ALL the bells and whistles of MS, or need to regularly transfer files between MS programmes on other computers and your laptop / desktop computer, then they might not be the best of ideas. Keynote - IME - can have some difficulties in transferring formatting to Powerpoint.
    Finally, there's MS Office Mac 2011. You can't download MS Office from the App Store, but can order the CDs from most online stores (including Apple's own store). It might be worth price hunting - if you're a student, you can usually find the programmes relatively cheap (£38 at the moment on Software4Students, though you'll need to belong to an academic institution / have a UK .ac email address). Apple's own prices on MS software are unlikely to be the best prices out there (though the product will be identical).
    MS Office includes Word, Excel and Powerpoint in the basic version. The slightly more expensive version (which, I think, is the £38 one on S4S) includes Outlook. Which - IME - is far more of a nuisance than Apple's native Mail programme.
    (I should probably add - I'm an academic. I own both Apple's own programmes, and MS Office 2011. I tend to use the MS programmes more, if only because they're the ones that other people tend to use, and transferring between Apple and MS programmes is a minor inconvenience. Pages also lacks Garamond, my favourite work font. The Apple progs are, however, far more beautifully integrated, and would be MORE than good enough for most users...)

  • BPC 7.5 NW Processing Dimensions Microsoft.Office.Interop.Excell issue

    Hi
    I've tried all the downloads (service Packs, Interop Files etc) mentioned in all websites and posts to try and fix following error:
    "Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel_Application'. This Opperation failed because the Query Interface call on the COM component for the interface with ID '{000208D5-0000-0000-C000-0000000000046}' failed due to the following error: Library not registered.
    I get this only when I try to Process a dimension
    Please can anyone tell me how to fix this?
    We have installed BPC 7.5 NW
    I had Office 2010 and could process but my input schedules didn't work 100% on Office 2007 so I had to go back to 2007. And now I can't process in the Admin Client. I've uninstalled and reinstalled Office and BPC 7.5 NW SP07 a few times to try and solve this but no luck.
    Thanks
    Johan Fourie

    Hi,
    If you are using excel 2007, you need to install the redistributable primary interop assembly from the below link:
    https://websmp230.sap-ag.de/sap%28bD1lbiZjPTAwMQ==%29/bc/bsp/sno/ui_entry/entry.htm?param=69765F6D6F64653D3030312669765F7361706E6F7465735F6E756D6265723D3134363332383926
    Hope this helps.

Maybe you are looking for