Possible Improvements

Nov 15, 2011 at 5:21 PM

Since I use Robocopy rather frequently, I took a look at this.  Even though I really like the idea and the long filename support, I have some concerns about this and how to use it.  The biggest issue I see is that you are writing this as if it were a command line tool instead of a Powershell function/script.  I've wanted a Powershell version of robocopy a long time, but this is a implementation of the original robocopy without most of the benefits of Powershell.  

Here are some of my main concerns:

  1. Named Parameters - Tab completion can then give you the list of parameters: Copy-RoboPower -<TAB>  to get a list of options.
    1. Instead of /S use -Recurse
      1. Implementing this could be done using the following in the Param section of the function: [Parameter()][switch]$Recurse
    2. Instead of /E use -Recurse plus -IncludeEmptyFolders
    3. Instead of /L use -ListOnly
  2. Use a module for this to improve readability and maintainability.
    1. Put 1 function per file and reference it in your .psm1 module file
      1. .  $PSScriptRoot\cleanupVariables.ps1
      2. .  $PSScriptRoot\isFileLocked.ps1
    2. Put C# code in .cs file and reference it the same way in add-type
      1. Add-Type -Path "$PSScriptRoot\RoboPowerCopyInfo.cs"  -ErrorAction SilentlyContinue -ReferencedAssemblies "Microsoft.VisualBasic" -Language CSharp -IgnoreWarnings
    3. Only export functions needed by the end user from the module so they don't see all the other functions
  3. Use PowerShell Verb-Noun naming for functions that are visible outside of the module
    1. Copy-RoboPower
  4. Inline function help - see "help about_comment_based_help" to get started. This allows you to do things like:
    1. help Copy-RoboPower -Parameter Source
    2. help Copy-RoboPower -Full

These suggestions would make RoboPowerCopy much more appealing to PowerShell users and make it fit in better with the PowerShell model.  Hope this helps some and I wish you good luck with this project.  It would be a good tool to have.