Alex's IT Blog
Contact Me
  • Home
  • IT Blog
  • Certification
  • Useful Links
  • Site Sponsors

Copy folder structure and only certain file types using Robocopy

8/2/2013

5 Comments

 
I am preparing our current and historic email data ready to send across to Mimecast for data ingestion. One of the things I need to do is take a copy of all our users' .PST files (aka Outlook Data Files) from their Home directories and store them all together on a storage disk across the network.

Now, I could manually run a search in Windows Explorer for all *.pst then copy them elsewhere. Problem with that is most of our users PST's are going be saved as the default 'Personal Folders(1).pst'  meaning Windows would constantly prompt me to overwrite or save both. Also, with this naming convention, once all PST's are in one big storage area, I would have no idea whose PST is who.

The only way I can think of getting round this is to use Robocopy.exe to replicate the Home directories folder structure onto the storage disk and only copy PST files, ignoring all other file types. This way, there would be no conflicts and prompts to overwrite and I would also know who's PST is who from the folder path.

On the server which contains the Home directories, run the following from command prompt:

ROBOCOPY d:\home \\storage\restores\temp
*.pst /S

d:\home is the drive and folder which contains the home directories for each user
\\storage\restores\temp is the server, share and folder where I want the folder structre and PST's to be copied
*.pst means that only .PST files will be copied
/S means the folder structure and any subfolders will be copied, only if they contain .PST files

Unfortunatley in my scenario there is still a bit of manual work required. I would need to go into each users home directory (on the copy on the storage disk), and rename each PST to Mimecasts required naming convention. To assist, you could create a script. The the easist way (that I know of) is to output the directory structure (dir /b /s *.pst >c:/pstdir.txt), open as an Excel file and use the concatenate function to firstly build the new filename, then a 'ren' (rename) command.
You should end up with something similar to below for each row which can be copied into a bat file or directly into command prompt.:
ren "\\storage\restores\temp\joe.bloggs\My Documents\Outlook Files\Personal Folders (1).pst" "joe.bloggs@domain.com.1.pst"

A list of Robocopy commands can be found here

5 Comments
Blake
19/2/2015 01:18:35 pm

I just went through the exact same process for Mimecast, but instead of using Excel and a rename operation, I wrote a powershell script to look at all the files and rename them based on the parent folder name. You need to use powershell to move all the PSTs into the home folder for each user then my script names all the files according to Mimecast requirements, including appending a number in sequence to the end of multiple files. If you are interested let me know and I will post.

Reply
Alex Heer
20/2/2015 04:08:56 am

Hi Blake,

Thanks for your comment. That's great you were able to accomplish this via powershell. unfortunately my Powershell wasn't (and still isn't) great hence why using other methods!

If you are happy to share your script I wouldn't mind seeing it (alex.heer85@gmail.com). If you want, I can attach to this post and attribute it to you via a link to a website or LinkedIn page?

Thanks

Reply
TwincleToes
21/10/2015 06:17:13 am

Hi Blake,

Please can you share the PS script.I am busy with the same project

Thanks!

Reply
Blake
10/11/2015 08:13:42 pm

Sure, If you give me your email I can send you the scripts I wrote for this.

Reply
Phillip
20/9/2016 12:29:51 pm

Hi Can you please email me the PowerShell script?
phill.gollogly@gmail.com
Thanks
Phillip

Reply



Leave a Reply.

    Author

    Alex Heer

    Archives

    June 2017
    March 2017
    January 2017
    October 2016
    August 2016
    June 2016
    May 2016
    March 2016
    February 2016
    October 2015
    September 2015
    August 2015
    July 2015
    April 2015
    March 2015
    January 2015
    December 2014
    September 2014
    July 2014
    June 2014
    May 2014
    April 2014
    March 2014
    February 2014
    January 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    July 2013
    June 2013
    May 2013
    April 2013
    March 2013
    February 2013
    January 2013

    Categories

    All
    Active Directory
    Awards
    Certification
    Cyber
    Dpm
    Exchange
    General Life
    Group Policy
    Home Computing
    Hyper V
    IIS
    Mcafee
    Microsoft Office
    Mimecast
    Networking
    Powershell
    Rds
    Security
    Server 2008 R2
    Server 2012
    Shoretel
    Social Media
    Sql
    Tmg
    Virtual Machines

    RSS Feed

Powered by
✕