我正在尝试替换命令行工具中的powershell值,但无法弄明白。
$a = "C:\Test\TestApp.exe"
$args = "arg1 arg2 arg3"
& schtasks /create /SC ONLOGON /TN "Test Task" /tr "'$a' $args" /F
//expected - schtasks /create /SC ONLOGON /TN "Test Task" /tr "'C:\Test\TestApp.exe' arg1 arg2 arg3" /F
答案 0 :(得分:2)
将$args
替换为$MyArgs
请参阅Get-Help about_Automatic_Variables
$Args
Contains an array of the undeclared parameters and/or parameter
values that are passed to a function, script, or script block.
When you create a function, you can declare the parameters by using the
param keyword or by adding a comma-separated list of parameters in
parentheses after the function name.
In an event action, the $Args variable contains objects that represent
the event arguments of the event that is being processed. This variable
is populated only within the Action block of an event registration
command. The value of this variable can also be found in the SourceArgs
property of the PSEventArgs object (System.Management.Automation.PSEventArgs)
that Get-Event returns.