Philip Loyer
Philip Loyer

Reputation: 768

Issues with spaces when executing powershell script from the command line

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.

Upvotes: 0

Views: 588

Answers (1)

henrycarteruk
henrycarteruk

Reputation: 13227

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>}"

Upvotes: 1

Related Questions