title: How do I turn this into a function?
body: <p>I found this script on this site &lt;thanks Nick!&gt;</p>
  <pre><code>   $files = gci $srcpath
  
  foreach ($srcfile in $files) {
    # Build destination file path
    $dstfile = [string]($dstpath, '\', $srcfile.name -join '')
  
    # Copy the file
    cp $srcfile.FullName $dstfile.FullName -whatif
  
    # Make sure file was copied and exists before copying over properties/attributes
    if ($dstfile.Exists) {
     # $dstfile.CreationTime = $srcfile.CreationTime
     # $dstfile.LastAccessTime = $srcfile.LastAccessTime
      $dstfile.LastWriteTime = $srcfile.LastWriteTime
     # $dstfile.Attributes = $srcfile.Attributes
     # $dstfile.SetAccessControl($srcfile.GetAccessControl())
    }
  }
  </code></pre>
  <p>I want to turn this into a function so it accepts recursive directories to copy the timestamps from the source, a cloud folder to it's equivalent at the destination.</p>
  <p>Now, I have tried calling the function using multiple variables, trying different methods such as:</p>
  <p>$src = $args[0]</p>
  <p>$dst = $args[1]</p>
  <p>Get-Timestamp $src, $dst</p>
  <p>either uses the default folder that the script is running or will fail when it tries to list the contents combining the 2 variables together.</p>
  <p>even setting up the function like so</p>
  <p>[CmdletBinding(DefaultParamerterSetName='Srcpath')]
  param (
  [Parameter(Mandatory = $true,
  ParameterSetName = 'Srcpath',<br />
  Position = 0)]
  [string[]]$Srcpath,</p>
  <pre><code>   # [Parameter(Mandatory = $true, 
     # ParameterSetName = 'DSTpath',
     # Position = 1)]
      [string]$DSTpath
      )
      $PSCmdlet.ParameterSetName
  </code></pre>
  <p>is not producing the expected result.</p>
  <p>This will work on its own, doing one folder at a time. But not when doing subfolders.</p>
  <p>Suggestions would be greatly appreciated.</p>