I can't figure out why the below code won't work:
Function createFirefoxTask() {
$schedule = new-object -com Schedule.Service
$schedule.connect()
$tasks = $schedule.getfolder("").gettasks(0)
foreach ($task in ($tasks | select Name)) {
echo "TASK: $task.name"
if($task.equals("FirefoxMaint")) {
write-output "$task already exists"
break
}
}
}
createFirefoxTask
The output I get is this:
FirefoxMaint
TASK: @{Name=FirefoxMaint}.name
TASK: @{Name=Task1}.name
TASK: @{Name=Task2}.name
TASK: @{Name=Task3}.name
TASK: @{Name=Task4}.name
TASK: @{Name=Task5}.name
If I echo $task.name
from the shell without going through the script, it properly displays the name.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…