Skip to content

Update-ServiceStatus - Fix WinRM error on machines without WinRM configured#10274

Merged
potatoqualitee merged 3 commits into
developmentfrom
claude/issue-9782-20260320-1904
Mar 28, 2026
Merged

Update-ServiceStatus - Fix WinRM error on machines without WinRM configured#10274
potatoqualitee merged 3 commits into
developmentfrom
claude/issue-9782-20260320-1904

Conversation

@andreasjordan
Copy link
Copy Markdown
Collaborator

Fixes #9782

Problem

When CIM instances are passed across runspace boundaries (via Invoke-Parallel), they become deserialized and lose their CIM session context. Subsequent calls to Invoke-CimMethod and Get-CimInstance then attempt to create a new connection using WinRM by default, which fails on machines where WinRM is not configured (e.g. fresh Azure VMs, machines before running winrm quickconfig).

This affected Enable-DbaAgHadr, Set-DbaNetworkConfiguration -RestartService, and any other command that calls Restart-DbaService / Stop-DbaService.

Fix

Modified $svcControlBlock in Update-ServiceStatus.ps1 to create a DCOM-based CIM session inside the runspace, which does not require WinRM. The session is used to get fresh CIM instances before invoking service control methods and for polling service state. Falls back to WinRM if DCOM is unavailable.

Generated with Claude Code

github-actions Bot and others added 2 commits March 20, 2026 19:15
…ace boundaries

When CIM instances are passed across runspace boundaries (via Invoke-Parallel),
they become deserialized and lose their CIM session context. Subsequent calls to
Invoke-CimMethod and Get-CimInstance then attempt to create a new connection using
WinRM by default, which fails on machines where WinRM is not configured.

The fix creates a DCOM-based CIM session inside the runspace scriptblock, avoiding
the WinRM dependency. The session is used to obtain fresh CIM instances before
invoking service control methods, and for polling service state during restart.
Falls back to WinRM if DCOM is unavailable.

Fixes #9782

(do *Service*)

Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
@andreasjordan andreasjordan marked this pull request as draft March 21, 2026 17:10
@andreasjordan
Copy link
Copy Markdown
Collaborator Author

This needs more testing in my lab before merging.

@andreasjordan
Copy link
Copy Markdown
Collaborator Author

It fixes the issue.

With current release of dbatools:
image

With this branch:
image

@andreasjordan andreasjordan marked this pull request as ready for review March 22, 2026 17:21
@potatoqualitee
Copy link
Copy Markdown
Member

hell yeah thank you! 🔥

@potatoqualitee potatoqualitee merged commit 99a4a90 into development Mar 28, 2026
14 checks passed
@potatoqualitee potatoqualitee deleted the claude/issue-9782-20260320-1904 branch March 28, 2026 07:23
potatoqualitee added a commit that referenced this pull request Apr 10, 2026
…use (review of #10274)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Enable-DbaAgHadr (and maybe other commands) failing with "Get-RunspaceData -wait" on a new maschine without WinRM configured

2 participants