This error translates to 267 "Invalid Directory" and happens when the working directory is handed to registration while being enclosed in quotes ..

so the obvious change is
line 35 to be:

 Code:
      $Action.WorkingDirectory = $workdir
_________________________