Skip to content

fix(scheduledtaskinfo): target remote CIM session and continue loop on per-task failure#43

Open
tablackburn wants to merge 1 commit into
mainfrom
fix/scheduledtaskinfo-remote-cim-session
Open

fix(scheduledtaskinfo): target remote CIM session and continue loop on per-task failure#43
tablackburn wants to merge 1 commit into
mainfrom
fix/scheduledtaskinfo-remote-cim-session

Conversation

@tablackburn
Copy link
Copy Markdown
Owner

Summary

  • 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.
  • The wrapper error was then raised via ThrowTerminatingError, aborting the entire loop on the first failing task.

Changes

Get-StmScheduledTaskInfo.ps1 — four changes:

  • 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{}

Behavior before vs after

Get-StmScheduledTaskInfo -ComputerName <remote> -TaskName 'ServerInventory*' -Credential $cred
Before After
Each task Get-ScheduledTaskInfo : The system cannot find the file specified. (HRESULT 0x80070002) Returns full task info
Loop behavior Aborts on first failing task Continues; failing tasks produce non-terminating errors

Test plan

  • ./build.ps1 UnitTest — all 20 tests in Get-StmScheduledTaskInfo.Tests.ps1 pass (3 new + 2 updated existing)
  • Lab-validated end-to-end on STMDC01 (remote standalone Windows host): pristine module reproduced the exact user-reported failure; patched module returns all 3 tasks with full info, zero errors
  • Backtick line-continuation scan — none introduced

Tests

New (3):

  • Get-StmScheduledTaskInfo.Remote-host CIM session plumbing (Issue 3 fix a).Should pass -CimSession to Get-ScheduledTaskInfo when ComputerName is a remote host
  • Get-StmScheduledTaskInfo.Remote-host CIM session plumbing (Issue 3 fix a).Should NOT pass -CimSession to Get-ScheduledTaskInfo when ComputerName is localhost
  • Get-StmScheduledTaskInfo.Loop continues on per-task failure (Issue 3 fix b).Should process remaining tasks (and write a per-task error) when one task fails

Updated (2): the existing Should throw terminating error... and Should include task name in error message tests asserted the bug behavior. Updated to assert the new (correct) WriteError + continue behavior.

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings May 19, 2026 01:07
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Warning

Rate limit exceeded

@tablackburn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 59 minutes and 19 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 554d4ed5-42d0-4a65-b602-9269af041c47

📥 Commits

Reviewing files that changed from the base of the PR and between ef4fade and 76658ad.

📒 Files selected for processing (2)
  • ScheduledTasksManager/Public/Get-StmScheduledTaskInfo.ps1
  • tests/Get-StmScheduledTaskInfo.Tests.ps1
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/scheduledtaskinfo-remote-cim-session

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...edTasksManager/Public/Get-StmScheduledTaskInfo.ps1 93.75% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -ComputerName values and pass it to Get-ScheduledTaskInfo.
  • Change error handling from ThrowTerminatingError to WriteError + continue to 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.

Comment on lines +233 to +241
$getScheduledTaskInfoParameters = @{
TaskName = $task.TaskName
TaskPath = $task.TaskPath
ErrorAction = 'Stop'
}
if ($infoCimSession) {
$getScheduledTaskInfoParameters['CimSession'] = $infoCimSession
}
$scheduledTaskInfo = Get-ScheduledTaskInfo @getScheduledTaskInfoParameters
Comment on lines 305 to +308
end {
if ($infoCimSession) {
Remove-CimSession -CimSession $infoCimSession -ErrorAction SilentlyContinue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants