0

I am trying to run the following script from the command with parameters. However I get this error, what am I doing wrong?

-File & "'C:\BB2 Images\MoveFiles.ps1'" -destinationRoot "\\OB-VM-ME-Data\ME-Data\Archived\BusbarTools\BB-2" -localPath & "'C:\BB2 Images'"

Processing -File ''C:\BB2 Images\MoveFiles.ps1'' failed: The given path's format is not supported. Specify a valid path for the -File parameter.

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Philip Loyer
  • 738
  • 2
  • 7
  • 22

1 Answers1

1

So long as the path is quoted as a string, most Powershell commands/functions handle spaces in the file path themselves. (see about_quoting_rules for difference between " " and ' ')

So only use one set of quotes in your command, you also don't need to use the & either:

[powershell] -File "C:\BB2 Images\MoveFiles.ps1" -destinationRoot "\\OB-VM-ME-Data\ME-Data\Archived\BusbarTools\BB-2" -localPath "C:\BB2 Images"

The & is used when calling a command (not when calling a file):

powershell -Command "& {<command>}"
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • 1
    Good advice, but just to clarify: you don't _need_ `& { ... }` to invoke a command: `powershell -Command ""` is sufficient; that is, there is no need to wrap a command in an extra script block. However, you do need `&` inside `` to invoke a command name/path specified as a _variable_ or a _quoted_ string. – mklement0 Nov 27 '18 at 20:32