2

I want to set up a scheduled task and need to ideally fit the following in one line. I have tried using a script block {} but does not seem to work.

I want to try and put

[String] $cmd = Get-Content \pathto\script.ps1
Invoke-Expression $cmd
$othercmd = abc xyz
Invoke-Expression $othercmd

How would I go about joining them in a one liner so I coud call powershell...?

I know I could put it in a script and call that from schtasks but I am interested to see if there is a way to join the commands.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
powerpig
  • 21
  • 1
  • 3
    PowerShell statements can be daisy-chained by putting semicolons between the statements. With that said, since you want to run the statements as a scheduled task you should put them in a script anyway. And you [shouldn't be using `Invoke-Expression`](https://blogs.msdn.microsoft.com/powershell/2011/06/03/invoke-expression-considered-harmful/) in the first place. – Ansgar Wiechers Jul 19 '19 at 07:23

0 Answers0