Skip to content

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

Draft
andreasjordan wants to merge 3 commits intodevelopmentfrom
claude/issue-9782-20260320-1904
Draft

Update-ServiceStatus - Fix WinRM error on machines without WinRM configured#10274
andreasjordan wants to merge 3 commits intodevelopmentfrom
claude/issue-9782-20260320-1904

Conversation

@andreasjordan
Copy link
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
Collaborator Author

This needs more testing in my lab before merging.

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

1 participant