批處理文件運行PowerShell腳本。問題是路徑位置有空格。批處理文件只能看到空格前的第一個單詞。批處理文件沒有正確添加文件夾結構與空格?
SET targetDir="\\server.com\xxx\First Folder with spaces\Second folder with spaces"
SET archiveDir="\\server.com\xxx\First Folder with spaces\Second folder with spaces\Archive"
SET siteID=ABC
REM Run the import Powershell script for files.
powershell.exe -File D:\localPath\powershell\PowerShellScript.ps1 -Path "%targetDir%" -Filter *.dlu -Site %siteID% -ArchiveDir "%archiveDir%"
所以,當我跑我的PowerShell腳本它得到的參數從批處理文件
param
(
[string] $Path = $(Throw "You must specify a directory path containing the files to import."),
[string] $Filter = $(Throw "You must provide a file pattern/filter (e.g. *.dlu) to be used for locating the files to import"),
[string] $Site = $(Throw "You must provide a site identifier for the import."),
[string] $ArchiveDir = $null # If not provided, the imported files will be deleted rather than archived to another location.
)
但是當我有輸出路徑到屏幕上,我得到:
Path= C:\First
Site= ABC
Archive= C:\First
什麼我做錯了嗎?
如果我使用硬代碼運行.bat文件,它的工作原理非常完美。
REM SET targetDir="\\server.com\xxx\First Folder with spaces\Second folder with spaces"
REM SET archiveDir="\\server.com\xxx\First Folder with spaces\Second folder with spaces\Archive"
REM SET siteID=ABC
REM Run the import Powershell script for files.
powershell.exe -File D:\localPath\powershell\PowerShellScript.ps1 -Path "\\server.com\xxx\First Folder with spaces\Second folder with spaces" -Filter *.dlu -Site ABC -ArchiveDir "\\server.com\xxx\First Folder with spaces\Second folder with spaces\Archive"
謝謝@MobyDisk那就是問題 –