Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 787 other subscribers


  • LinkedIn
  • RSS Feed for Posts
  • Twitter
  • StumbleUpon

Move files to sub folders based upon year and month LastWriteTime [Solved]

Very often I hear my colleagues say that zipping, deleting or archiving a folder takes to many time, and resources of the server they are working on.

This is due to the large amount of files in these folders.


In order to help then I write this simple script, to move files based upon their LastWriteTime.

The scripts looks at the LastWriteTime, and creates subfolders based upon year and month.



When working with a large amount of files, the server can give the message: ‘Not responding’

This is due to excessive use of resources of the server.


Always be aware of the server you’re working on, and the time you’re using this script.


Copy the powershell script, to a location on your server, for example c:\scripts


In this example the folder with the large amount files is F:\Test


Start Powershell as an administrator


Change the directory to the location where the script is located C:\scripts\Copy-files-Year-Month

Execute the script :



Fill in the location of the folder which contains the files.


This action can take a while based upon the amount of files to be moved.


All of the files are moved to the sub folders based upon year and month

Your now able to zip,archive of delete the files in smaller groups based upon one or more folders.




2 comments to Move files to sub folders based upon year and month LastWriteTime [Solved]

  • Hi love the script

    Could you help me.

    with a modification to this script.

    I have a root folder with several sub folders

    c://root/ many-subfolders/ many-logfiles.

    I would like the sctipt to sort long files yer month and output to the orginal subfolder excluding files from current year


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.