| « Rename HyperV export for import (clone) | Function IndexOfArray » |
Because I encountered a lot of strugle to create some scheduled tasks on a Windows 2003 machine with PowerShell v2.0.
I used the function of Hugo Peeters (see the link) and then I encountered a problem to pass a task with a parameter between double quotes.
Create-ScheduledTask -ComputerName $Server -TaskName '`"Name`"' -TaskRun '`"C:\WINDOWS\system32\cscript.exe \`"C:\test script\script.vbs\`"`"' -Schedule "DAILY" -StartTime "08:00" -RunAsUser "$domain\$User" -RunAsPwd $Password -Days "*"
This is the only format I used that worked to create a scheduled task to start a vbscript or another task including a parameter. Follow up:
[codespan]
# -----------------------------------------------------
# Creates a scheduled task
Function Create-ScheduledTask
{
# '@ http://www.peetersonline.nl/index.php/powershell/managing-scheduled-tasks-remotely-using-powershell/ '@
param(
[string]$ComputerName = "localhost",
[string]$RunAsUser = "System",
[string]$RunAsPwd = "",
[string]$TaskName = "MyTask",
[string]$TaskRun = '"C:\Program Files\Scripts\Script.vbs"',
[string]$Schedule = "Monthly",
[string]$Modifier = "second",
[string]$Days = "SUN",
[string]$Months = '"MAR,JUN,SEP,DEC"',
[string]$StartTime = "13:00",
[string]$EndTime = "17:00",
[string]$Interval = "60"
)
#$Command = "schtasks.exe /create /s $ComputerName /ru $RunAsUser /tn $TaskName /tr $TaskRun /sc $Schedule /mo $Modifier /d $Days /m $Months /st $StartTime /et $EndTime /ri $Interval /F"
$Command = "schtasks.exe /create /s $ComputerName /ru $RunAsUser /rp $RunAsPwd /tn $TaskName /tr $TaskRun /sc $Schedule /st $StartTime /F"
Invoke-Expression $Command
Clear-Variable Command -ErrorAction SilentlyContinue
}
# -----------------------------------------------------
Create-ScheduledTask -ComputerName $Server -TaskName '`"Name`"' -TaskRun '`"C:\WINDOWS\system32\cscript.exe \`"C:\test script\script.vbs\`"`"' -Schedule "DAILY" -StartTime "08:00" -RunAsUser "$domain\$User" -RunAsPwd $Password -Days "*"
[/codespan]
5 comments
-
§ szybki program do Å›ciÄ…gania filmów said on : 2424-03-2010 @ 00:07
I came across your site, i think your site is interesting, keep us posting.
-
§ Yareli said on : 0202-04-2010 @ 18:53
I agree with the author. Thanks
-
§ Wilma said on : 1919-05-2010 @ 12:24
I just found this post by search engine, you got something interesting topics here. Definitely going to visit daily. Cheers.
-
§ Miguel
said on : 1818-06-2010 @ 05:19
thanks for the article. It was very ineresting for me. -
§ how to make money blogging said on : 1515-07-2010 @ 02:48
its really very nice and informative posting thanks for sharing this with us...