我是新來的PowerShell腳本,我在一個Windows Server 2003上與schtasks堅持。 我知道問題是轉義,但無法解決它。與powershell腳本中的schtasks問題
[string]$a = "-command `"Powershell $b > $c`""
$d = "C:\powershell.exe";
其中$ b爲PowerShell腳本的路徑(C:\ filename.ps1) $ c是日誌文件的路徑(C:\登錄\ filename.log)
當我嘗試使用schtaks
schtasks /create /sc weekly /d $tsk.DofW /st $tsk.At /tn "$tsk.name" /tr "$d $($a)"
我得到一個錯誤說無效的參數/選項計劃任務 - 'C:\ filename.ps1'
任何幫助表示讚賞
編輯
如果我這樣做,你怎麼提到它運行沒有任何錯誤,但是當我看 任務調度操作選項卡下,它的細節Ç說:\ powershell.exe System.Collections.Hashtable。 args 而不是powershell.exe - 命令「Powershell C:\ filename.ps1> C:\ log \ filename.log」。 如果我添加一個額外的支架,如「$ d $($ a)」在schtasks中,我得到一個錯誤,說無效參數/選項「>」
如果您要在CMD中輸入命令,它會是什麼樣子? 'schtasks/Create/sc WEEKLY/d MON/st 13:13/tn FOO/tr'C:\ PowerShell.exe -command「&C:\ filename.ps1 | Out-File C:\ log \ filename.log」 ' –