Hi. I have a problem to use the status of a specific task in task scheduler to send notification if task from "Ready" to "Running" go.
I did so:
$TaskName="Test task" function GetTaskState() { $task=Get-ScheduledTask | Where TaskName -eq "$TaskName" $taskstate=$task.State } $Count=1 While ($task.State -eq 'Running') { TaskProc = GetTaskState; Start-Sleep -Seconds 60 ;$count++ } if (($task.State -eq 'Ready') -and ($Count2 -gt "5")) { "Task state is Ready " } Else { "Warning.Task stopped" ; Exit }
Just did so:
do { $1 = Get-ScheduledTask | Where TaskName -eq "$TaskName" } While ($1.State = 'Ready')
And get error:
'State' is a ReadOnly property. At line:7 char:10 + } While ($1.State = 'Ready') + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException
Help Please, does not work :(