title: Powershell to copy files over network
body: <p>Trying to copy some files from server locally to network share as shown in the images below:</p>
  
  <p><strong>Folder 1</strong></p>
  
  <p><a href="https://i.stack.imgur.com/gQWyi.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gQWyi.png" alt="enter image description here"></a></p>
  
  <p><strong>Folder 2</strong></p>
  
  <p><a href="https://i.stack.imgur.com/xIjmI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xIjmI.png" alt="enter image description here"></a></p>
  
  <p>I need to achieve is copy all the contents of ROOT folder under SOURCE to DESTINATION folder. But each time it copies the content, I would like it to create a new folder with same destination folder name but suffixed with some sort of sequential numbering. The number of folders &amp; files within the SOURCE/ROOT folder always stays the same (2 folders &amp; 2 files). I just need all those source content go into a new folder on the destination each time I run the script. Here is an example of a script I have been trying out but it's just not doing what I need:</p>
  
  <pre><code>$date = Get-Date -format MMMM-dd-yyyy
  $date2 = Get-Date -format yyyyMMdd
  
  $Source = "C:\SOURCE\ROOT"
  
  $Destination1 = "\\netshare\DESTINATION\DATA_May-26-2014"
  $Destination2 = "\\netshare\DESTINATION\DATA_May-26-2014-1st"
  $Destination3 = "\\netshare\DESTINATION\DATA_May-26-2014-2nd"
  $Destination4 = "\\netshare\DESTINATION\DATA_May-26-2014-3rd"
  $Destination5 = "\\netshare\DESTINATION\DATA_May-26-2014-4th"
  $Destination6 = "\\netshare\DESTINATION\DATA_May-26-2014-5th"
  
  #Check destination path
  if (Test-Path $Destination1)
   {
    #then copy
    robocopy $Source $Destination2 /MIR /Z /E /fft /MAXAGE:$date2
   }
  if (Test-Path $Destination2)
   {
    #then copy
    robocopy $Source $Destination3 /MIR /Z /E /fft /MAXAGE:$date2
   }
  if (Test-Path $Destination3)
   {
    #then copy
    robocopy $Source $Destination4 /MIR /Z /E /fft /MAXAGE:$date2
   }
  if (Test-Path $Destination4)
   {
    #then copy
    robocopy $Source $Destination5 /MIR /Z /E /fft /MAXAGE:$date2
   }
  if (Test-Path $Destination5)
   {
    #then copy
    robocopy $Source $Destination6 /MIR /Z /E /fft /MAXAGE:$date2
   }
  else
   {
    robocopy $Source $Destination1 /MIR /Z /E /fft /MAXAGE:$date2
   }
  </code></pre>
  
  <p>I was initially using robocopy only for a similar purpose but this copying project needed the folder to have the month name along with it (as in "May") which was not available with robocopy and so I had to switch to powershell script and combine robocopy.</p>
  
  <p>Any ideas on how I can create a better script?</p>