fix(scheduledtaskinfo): target remote CIM session and continue loop on per-task failure#43
fix(scheduledtaskinfo): target remote CIM session and continue loop on per-task failure#43tablackburn wants to merge 1 commit into
Conversation
…n per-task failure
Get-StmScheduledTaskInfo -ComputerName <remote> was calling Get-ScheduledTaskInfo
without -CimSession, causing every task lookup to fall back to the local Task
Scheduler and fail with HRESULT 0x80070002 ("file not found") for tasks that
exist on the remote host but not locally. The error was then wrapped via
ThrowTerminatingError, which aborted the entire loop on the first failing task.
Four changes, one file:
- Create a CIM session in begin{} when ComputerName is not the local host
(and not "." or $env:COMPUTERNAME)
- Pass -CimSession to Get-ScheduledTaskInfo when one is available
- Replace ThrowTerminatingError with WriteError + continue so per-task failures
are non-terminating and the loop processes the remaining tasks
- Clean up the CIM session in end{}
Three new Pester tests plus two existing tests updated to reflect the corrected
behavior. The existing "Should throw terminating error" tests were asserting
the bug; they now assert the fix (non-terminating error + loop continues).
Lab-validated end-to-end on a remote standalone Windows host (the lab's DC):
pristine module reproduced the exact user-reported failure (0x80070002 + loop
abort); patched module returns full data with zero errors.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR fixes remote scheduled-task info retrieval by ensuring Get-StmScheduledTaskInfo -ComputerName <remote> queries the remote Task Scheduler (via CIM session) and changes per-task failures from terminating to non-terminating so the loop continues.
Changes:
- Create/cleanup a CIM session for remote
-ComputerNamevalues and pass it toGet-ScheduledTaskInfo. - Change error handling from
ThrowTerminatingErrortoWriteError+continueto avoid aborting the entire loop. - Update/add Pester tests to validate CIM session plumbing and non-terminating per-task failures.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
ScheduledTasksManager/Public/Get-StmScheduledTaskInfo.ps1 |
Adds remote CIM session usage for Get-ScheduledTaskInfo, changes failure handling to non-terminating, and cleans up the session. |
tests/Get-StmScheduledTaskInfo.Tests.ps1 |
Adds/updates tests for remote CIM session parameter passing and for continuing the loop after per-task failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $getScheduledTaskInfoParameters = @{ | ||
| TaskName = $task.TaskName | ||
| TaskPath = $task.TaskPath | ||
| ErrorAction = 'Stop' | ||
| } | ||
| if ($infoCimSession) { | ||
| $getScheduledTaskInfoParameters['CimSession'] = $infoCimSession | ||
| } | ||
| $scheduledTaskInfo = Get-ScheduledTaskInfo @getScheduledTaskInfoParameters |
| end { | ||
| if ($infoCimSession) { | ||
| Remove-CimSession -CimSession $infoCimSession -ErrorAction SilentlyContinue | ||
| } |
Summary
Get-StmScheduledTaskInfo -ComputerName <remote>was callingGet-ScheduledTaskInfowithout-CimSession, causing every task lookup to fall back to the local Task Scheduler and fail with HRESULT 0x80070002 ("file not found") for tasks that exist on the remote host.ThrowTerminatingError, aborting the entire loop on the first failing task.Changes
Get-StmScheduledTaskInfo.ps1— four changes:begin{}whenComputerNameis not the local host (and not.or$env:COMPUTERNAME)-CimSessiontoGet-ScheduledTaskInfowhen one is availableThrowTerminatingErrorwithWriteError+continueso per-task failures are non-terminating and the loop processes the remaining tasksend{}Behavior before vs after
Get-ScheduledTaskInfo : The system cannot find the file specified.(HRESULT 0x80070002)Test plan
./build.ps1 UnitTest— all 20 tests inGet-StmScheduledTaskInfo.Tests.ps1pass (3 new + 2 updated existing)STMDC01(remote standalone Windows host): pristine module reproduced the exact user-reported failure; patched module returns all 3 tasks with full info, zero errorsTests
New (3):
Get-StmScheduledTaskInfo.Remote-host CIM session plumbing (Issue 3 fix a).Should pass -CimSession to Get-ScheduledTaskInfo when ComputerName is a remote hostGet-StmScheduledTaskInfo.Remote-host CIM session plumbing (Issue 3 fix a).Should NOT pass -CimSession to Get-ScheduledTaskInfo when ComputerName is localhostGet-StmScheduledTaskInfo.Loop continues on per-task failure (Issue 3 fix b).Should process remaining tasks (and write a per-task error) when one task failsUpdated (2): the existing
Should throw terminating error...andShould include task name in error messagetests asserted the bug behavior. Updated to assert the new (correct)WriteError+continuebehavior.🤖 Generated with Claude Code