So the question is, i can get the job tracker items via $jobtrackerlist.job. But how can i make them announce they are complete? I would rather not be constantly be sending schtasks commands out at PC's and would rather them somehow report back that they are done.
Here's what I'm working with
I have a timer that will query the $jobtrackerlist and then update the datagridview with the info received. This will trigger once and run the duration of the GUI instance.
- function start-thisjob
- {
- $namer = $source
- Add-JobTracker -Name $namer `
- -JobScript {
- Param ($namer)
- $n = Get-Process $PID
- while ($n.hasexited -ne $TRUE)
- {
- $Jobs = $JobTrackerList.job
- }
- }`
- -CompletedScript {
- Param ($Job)
- }`
- -UpdateScript {
- Param ($Jobs)
- $results = New-Object System.Collections.ArrayList
- foreach ($item in $jobs)
- {
- $thistracker = { } | select "Name", "Status", "Starttime"
- $thistracker.Name = $item.name
- $thistracker.status = $item.state
- $thistracker.starttime = $item.psbegintime
- $results += $thistracker
- }
- Update-DataGridView -DataGridView $DGV_jobstatus -Item $results -AutoSizeColumns DisplayedCells
- }
- }
- #This
- Add-JobTracker -Name $source `
- -JobScript {
- Param ($source)
- $PID
- $n = $null
- New-Item -ItemType file -Value $null -Path \\$using:source\c$\usmtfiles\status.txt
- # $statustext = Get-Content \\$using:source\c$\usmtfiles\status.txt
- while ($statustext -ne 'complete')
- {
- Start-Sleep 1000
- $statustext = Get-Content \\$using:source\c$\usmtfiles\status.txt
- }
- }`
- -CompletedScript {
- Param ($Job)
- Write-Host $Job + 'Completed'
- }`
- -UpdateScript {
- Param ($Job)
- #$jobs = $JobTrackerList.job | select State, Name, Progress, PSBeginTime
- #Update-DataGridView -DataGridView $DGV_jobstatus -Item $jobs -AutoSizeColumns DisplayedCells
- }
- }
Currently I'm getting just a single job showing up (the most recent job) and it just sits as running forever. Not looking for you to write this whole thing for me, just maybe a hint as to how the jobtracker Command interacts with the "Update-jobtracker". Like the update-jobtracker can interact with the form and can use information provided by the param $jobs?? Maybe this is not a use case for jobtracker?