簡體   English   中英

從命令行執行Powershell腳本時出現空格問題

[英]Issues with spaces when executing powershell script from the command line

我試圖從帶有參數的命令中運行以下腳本。 但是我收到此錯誤,我在做什么錯?

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

處理文件“ C:\\ BB2 Images \\ MoveFiles.ps1”失敗:不支持給定路徑的格式。 為-File參數指定有效路徑。

只要路徑被引用為字符串,大多數Powershell命令/函數都會自己處理文件路徑中的空格。 (有關" "' '區別,請參見about_quoting_rules

因此,僅在命令中使用一組引號,您也不需要使用&

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

所述&調用命令時(未調用文件時)時:

powershell -Command "& {<command>}"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM