将powershell值传递给命令行工具

将powershell值传递给命令行工具,powershell,Powershell,我正在尝试替换命令行工具中的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 a

我正在尝试替换命令行工具中的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

$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.

$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.