Powershell - COPY FOLDERS, SUB-FOLDERS, FILES OVER "DAYSOLD" TO ARCHIVE

COPY FOLDERS, SUB-FOLDERS, FILES OVER "DAYSOLD" TO ARCHIVE 


##  $SOURCEPATH = SOURCE PATH OF FOLDERS TO LOOK AT
##  $DESTINATIONPATH = THE PATH TO THE BACKUP / ARCHIVE LOCATION
##  $LOGPATH = THE PATH TO STORE LOG FILES IN
##  $FOLDERLIST = THE SUBFOLDERS OF SOURCEPATH TO SEARCH FOR ARCHIVE ELIGIBLE FILES
##  $DAYSOLD = MINIMUM AGE OF FILES (IN DAYS) TO MOVE TO ARCHIVE LOCATION

$sourcepath="C:\SOURCE\SOURCEFILES"
## FOLDER PATH MUST BE PRESENT
$destinationpath="\\SERVER\SHARE\"
## FOLDER PATH MUST BE PRESENT
$logpath="C:\SCRIPTS\LOGS\"
$folderlist = @("Documents","MY Music","projects","budgets","Pictures","misc")
$daysold=365
##  CREATE DYNAMIC TIME STAMPED FILE NAME FOR LOG
$logfilename = Get-Date -format "yyyy-MM-dd--hh-mm"
$logfilename = "MyArchiveName-"+$logfilename+".txt"
##  CREATE THE LOG FILE FOR THIS ROBOCOPY RUN TO APPEND TO
New-Item $logpath$logfilename -ItemType file
$options = ("/E", "/COPYALL", "/MOV", "/MT", "/DCOPY:DAT", "/MINAGE:$daysold", "/LOG+:$logpath$logfilename","/TEE")
##  RUN ROBOCOPY COMMAND FOR EACH FOLDER LISTED IN FOLDERLIST
FOREACH ($folder in $folderlist)
{
robocopy  $sourcepath$folder $destinationpath$folder $options
}