Reputation: 18848
I am trying to replace the powershell values in the command line tool but couldn't figure it out.
$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
Upvotes: 0
Views: 61
Reputation:
Replace $args
with a different var like $MyArgs
See this excerpt from 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.
Upvotes: 2