スケジュールタスクはpowershellでスケジュールされたタスクの作成をスクリプトしようとしています。スケジュールタスクはスペースを含むディレクトリにあるpowershellスクリプトを呼び出します。だから私はたpowershell.exe -noninteractive -command「& 『はC:\ tempに\プログラムファイル\ a.ps1』」のように/ trの引数で作成する必要があります。ここWindowsはpowershellでタスク作成の問題をスケジュールします
することは、私が試したもののサンプルです
私は-commandを交換したい# Create the script file the schedule task will call, note path contains a space
'set-content c:\temp\program files\a.log "Just done @ $(get-date)"' > 'c:\temp\program files\a.ps1'
$scriptFilePath = 'c:\temp\program files\a.ps1';
$userName = read-host 'user name'; # will need log on as batch rights
$userPassword = read-host 'user password';
# The following looks good but schtasks args gets messed up so no creation
$taskToRun = "c:\windows\system32\windowspowershell\v1.0\powershell.exe -noninteractive -command `"& '$scriptFilePath'`"";
$taskToRun
schtasks /create /tn 'ATest' /ru $userName /rp $userPassword /sc MINUTE /mo 1 /st '00:00' /f /tr $taskToRun;
# Gets imported but mangles the tr so instead of
$taskToRun = 'c:\windows\system32\windowspowershell\v1.0\powershell.exe -noninteractive -command \"& ''' + $scriptFilePath + '''\"';
$taskToRun
schtasks /create /tn 'ATest' /ru $userName /rp $userPassword /sc MINUTE /mo 1 /st '00:00' /f /tr $taskToRun;
事前に誰が正しくエスケープする方法を知っている場合は、私はヒントをいただければ幸いです
おかげ
パット
Powershellにはセミコロン行ターミネータは必要ありません。行に複数のステートメントがある場合にのみ、 ';'を使用してください。 – vonPryz
私はそれらが必要ではない、ただの習慣であることを知っています – pmcgrath
完全なソースコードを持つ最終的な解決策? – Kiquenet