PS: Archiving For File Servers

1 minute read


I wanted to see about creating an archive from our file server so that I could move data that is older to another directory. My favorite tool is Powershell, but I really like using Robocopy for any kind of file structure syncs. Either way, the following guide can be used in order to create an Archive for your file server.

NOTE: In this example, I wanted to move all files older than a year to another location.

To Resolve:

  1. Before touching any real data, always start by testing POC (Proof of Concept):

a. Create “C:\Test” on your local machine.

b. Create “C:\Test2” on your local machine.

c. Create some random text files in C:\Test and change their security properties e.g. Disable inheritance – Remove default user groups – Add some – Change their permissions, ect.

  1. Open up a Powershell window and run:

a. Load the following function (I would just use ISE for one time use. If you do this often, put it in your profile):

Function Set-Filetimestamps
Param (
[Datetime]$Date = (Get-Date))

Get-Childitem -Path $Path -Recurse |
Foreach-Object {
$_.Creationtime = $Date
$_.Lastaccesstime = $Date
$_.Lastwritetime = $Date }

# Now we run it:
Set-Filetimestamps -Path C:\Test -Date 7/1/2011
  1. You can now see that all the time stamps changed for that folder and it’s directory. Now we will create a function that moves older files to the C:\test2 folder and leaves any new ones:

a. Inside C:\test, create a couple new text documents and sub directories. They should obviously have today’s date instead of an older date.

Function Move-Toarchive
Param (

New-Psdrive -Psprovider Filesystem -Root $Path -Name Path

Cd $Path

Get-Childitem -Recurse |
Where-Object {$_.Lastwritetime -Lt (Get-Date).Adddays(-$Days)} |
Move-Item -Destination $Dest -Force

# Now we run it:
Move-Toarchive -Path C:\Test -Days 365 -Dest C:\Test2
  1. That’s it! Run the second script on a file server of your choice using the parameters you want.

These can be found in my gwFileSystem section.