Skip to main content
expanded answer
Source Link
Ansgar Wiechers
  • 197.9k
  • 26
  • 274
  • 344

Get-Content -Raw returns a string, which is not interpreted by PowerShell and cannot be passed as-is to the parameter -Action. Remove New-ScheduledTaskAction -Execute and -Argument from sch_task_action_final.conf and change

$sch_task_action = Get-Content c:\automation\sch_task_action_final.conf -Raw

to

$action, $params = (Get-Content C:\automation\sch_task_action_final.conf -Raw) -split ' ', 2
$sch_task_action = New-ScheduledTaskAction -Execute $action -Arugment $params

Alternatively you could use Invoke-Expression:

$sch_task_action = Invoke-Expresssion (Get-Content c:\automation\sch_task_action_final.conf -Raw)

but I wouldn't recommend that.

Remove New-ScheduledTaskAction -Execute and -Argument from sch_task_action_final.conf and change

$sch_task_action = Get-Content c:\automation\sch_task_action_final.conf -Raw

to

$action, $params = (Get-Content C:\automation\sch_task_action_final.conf -Raw) -split ' ', 2
$sch_task_action = New-ScheduledTaskAction -Execute $action -Arugment $params

Get-Content -Raw returns a string, which is not interpreted by PowerShell and cannot be passed as-is to the parameter -Action. Remove New-ScheduledTaskAction -Execute and -Argument from sch_task_action_final.conf and change

$sch_task_action = Get-Content c:\automation\sch_task_action_final.conf -Raw

to

$action, $params = (Get-Content C:\automation\sch_task_action_final.conf -Raw) -split ' ', 2
$sch_task_action = New-ScheduledTaskAction -Execute $action -Arugment $params

Alternatively you could use Invoke-Expression:

$sch_task_action = Invoke-Expresssion (Get-Content c:\automation\sch_task_action_final.conf -Raw)

but I wouldn't recommend that.

Source Link
Ansgar Wiechers
  • 197.9k
  • 26
  • 274
  • 344

Remove New-ScheduledTaskAction -Execute and -Argument from sch_task_action_final.conf and change

$sch_task_action = Get-Content c:\automation\sch_task_action_final.conf -Raw

to

$action, $params = (Get-Content C:\automation\sch_task_action_final.conf -Raw) -split ' ', 2
$sch_task_action = New-ScheduledTaskAction -Execute $action -Arugment $params