none
Retrieve *.ost and *.pst from all users with best performance way RRS feed

  • Question

  • Hi Guy!

    Actually I am running this code from a batch script  with good performance (I know that both FOR can be merged into one, but I don't knew how) :

    pushd c:\users
    for /r %%i in (*.ost) do echo %%i > c:\test.txt
    for /r %%i in (*.pst) do echo %%i >> c:\test.txt

    Now I need more info about pst and ost files such size (in MB) and last modified date.
    So, I tried with excellent powershell lang (I am learning it): 

    get-childitem -path c:\users -recurse -force -dept 6 -filter *.ost | select-object name, directory, @{name='Size_MB';expression={$_.length /1MB -as [int]}}, lastwritetime | Sort-Object -Property Size_MB -Descending | out-file c:\test.txt
    get-childitem -path c:\users -recurse -force -dept 6 -filter *.pst | select-object name, directory, @{name='Size_MB';expression={$_.length /1MB -as [int]}}, lastwritetime | Sort-Object -Property Size_MB -Descending | out-file -append c:\test.txt

    This is good enough but could be better...  I use -filter parameter because is more efficient that "-include *.pst, *.ost" wich take toooooo long to a shutdown script by gpo. But have to run get-childitem twice.

    On batch script I user FOR to search *.pst and *.ost and is more quickly than get-childitem -filter (I tested targeting the same files in the same PC) Beside I reduced the amount folders with "-dept 6".

    There is any way to run this in one line and with the best performance?
    Please need "for" and "get-childitem" examples to test it on powershell

    I did not know migrate the FOR from batch to powershell ... I suspect that the FOR will be more quickly!

    Thanks for your time!

    Thursday, November 23, 2017 3:24 PM

All replies

  •     for /r %%i in (*.ost *.pst) do echo %%i %%~ai %%~zi > c:\test.txt

    See for /? for help.

    More easy

        dir c:\users\*.pst c:\users\*.ost /a /s > c:\test.txt


    David Candy

    Thursday, November 23, 2017 9:42 PM
  • Hi David,

    Many thanks for your reply.  That is close... but I wanna migrate to powershell... so, I need use the FOR in the powershell script... not in batch.

    I mean, replace the whole "get-childitem" verb by "for". This will get me a files list and then I will pipe  to the "select-objet" to retrieve only the data that I need and in the format that I want.

    Many thanks again for your help!

    Friday, November 24, 2017 9:15 AM
  • David, I have found this solution which is very quick:

    get-childitem -path C:\users\*\AppData\Local\Microsoft\Outlook*  -recurse -force -dept 1 -include *.ost, *.pst | select-object fullname, @{name='Size_MB';expression={$_.length /1MB -as [int]}}, lastwritetime | Sort-Object -Property Size_MB -Descending | out-file c:\test.txt
    

    But is not too accurate... because will lost any *.ost, *.pst placed out of that path

    Friday, November 24, 2017 10:41 AM
  • David, this work great:

    get-childitem -path C:\users\*\AppData\Local\Microsoft\Outlook*  -recurse -force -dept 1 -include *.ost, *.pst | select-object fullname, @{name='Size_MB';expression={$_.length /1MB -as [int]}}, lastwritetime | Sort-Object -Property Size_MB -Descending | out-file c:\test.txt

    But if it doesn't find any file, don't get any answer.

    Can I put something like "No file was found" ?

    I have tried a lot but nothing works... :(

    Tuesday, December 12, 2017 3:39 PM
  • The Softaken OST to PST Converter Software, you can easy to move OST file to Outlook PST file format. It has a simple user-friendly interface, which help the software without any technical supports. There is no need for installation and configuration of Microsoft Outlook during the conversion process. It exports OST data to PST and many more formats like- EML, MSG, MBOX, HTML, and  EMLX, 
    Friday, January 24, 2020 8:41 AM