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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.