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.

4
  • Why do you use " and '? Commented Nov 27, 2018 at 15:17
  • I had read on here that was how to tackle the problem. But it did not work Commented Nov 27, 2018 at 15:19
  • Try -File &("C:\BB2 Images\MoveFiles.ps1") Commented Nov 27, 2018 at 15:20
  • Well the error is different now. it say -destinationRoot was unexpected at this time. Which is one of m parameters Commented Nov 27, 2018 at 15:30

1 Answer 1

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>}"
Sign up to request clarification or add additional context in comments.

1 Comment

Good advice, but just to clarify: you don't need & { ... } to invoke a command: powershell -Command "<command>" is sufficient; that is, there is no need to wrap a command in an extra script block. However, you do need & inside <command> to invoke a command name/path specified as a variable or a quoted string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.