0

I need to use Powershell v2 to create a new scheduled task. what I tried so far is the task scheduler com object as follows:

$task_path = "c:\Temp\tasks\*.xml"
$task_user = "Administrator"
$task_pass = "mypass"

$sch = New-Object -ComObject("Schedule.Service")
$sch.connect("localhost")
$folder = $sch.GetFolder("\")

Get-Item $task_path | %{
    $task_name = $_.Name.Replace('.xml', '')
    $task_xml = Get-Content $_.FullName

    $task = $sch.NewTask($null)

    $task.XmlText = $task_xml

    $folder.RegisterTaskDefinition($task_name, $task, 6, $task_user, $task_pass, 1, $null)
}

Now the problem i'm facing with this is that i don't want to specify any additional info in the method RegisterTaskDefinition other than the task name and the task object, because everything is in the XML file, even the username and password.

How to do this?

1 Answer 1

2

try this:

schtasks.exe /Create /XML C:\task.xml /tn taskname

Hope it helps!

Not the answer you're looking for? Browse other questions tagged or ask your own question.