Here is the function I call in my script:
Function SetUp-ScheduledTasks
{
param
(
[string]$Server = "",
[string]$TaskName = "",
[string]$ReleasePath = "",
[string]$User = "",
[string]$Pwd = ""
)
try
{
Set-ExecutionPolicy RemoteSigned
Remove-ScheduledTask -ComputerName $Server -TaskName $TaskName Get-ScheduledTask
Create-ScheduledTask -ComputerName $Server -TaskName $TaskName -TaskRun $ReleasePath -Schedule "DAILY" -StartTime "02:00:00" -RunAsUser $User -RunAsPwd $Pwd
exit 1
}
catch
{
exit 0
}
}
When I call this from within the Powershell_ISE in the script file but outside any function, it works perfectly, here's what I do for that: SetUp-ScheduledTasks "myserver" "MyTask1" "c:\release" "theuser" "thepassword"
However when I call it from PS command line like this:
. .\ScheduledTasks.ps1 SetUp-ScheduledTasks "myserver" "MyTask1" "c:\release" "theuser" "thepassword" It does not do anything.
I also tried qualifying each parameter with a dash and name, but that still didn't work.
What am I missing?
Thanks!