dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

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

Open andreasjordan opened this issue 4 months ago • 6 comments

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

When using PowerShell ISE:

PS C:\Users\initialAdmin> Enable-DbaAgHadr -SqlInstance $sqlInstance[1, 2] -Force
WARNING: [14:07:51][Stop-DbaService] Multi-threaded execution returned an error | The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is a
ccepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the d
estination to analyze and configure the WinRM service: "winrm quickconfig".

WARNING: [14:08:15][Stop-DbaService] Multi-threaded execution returned an error | The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is a
ccepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the d
estination to analyze and configure the WinRM service: "winrm quickconfig".
ComputerName InstanceName SqlInstance          IsHadrEnabled
------------ ------------ -----------          -------------
SQL2022      SQLInstance2 SQL2022\SQLInstance2          True
SQL2022      SQLInstance3 SQL2022\SQLInstance3          True
PS C:\Users\initialAdmin> $null = Set-DbaNetworkConfiguration -SqlInstance $sqlInstance[1] -StaticPortForIPAll 14333 -RestartService
WARNING: [14:10:02][Set-DbaNetworkConfiguration] A restart of the service for instance SQLInstance2 on SQL2022 failed (The client cannot connect to the destination specified in the request. Verify that the service o
n the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM servic
e, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".). Restart of instance is necessary for the new settings to take effect.

When using powershell.exe:

PS C:\Users\initialAdmin> Set-DbaNetworkConfiguration -SqlInstance SQL2022\SQLInstance2 -StaticPortForIPAll 14338 -RestartService -Confirm:$false                                    Get-RunspaceData : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult   the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command  on the destination to analyze and configure the WinRM service: "winrm quickconfig".                                                                                                  At line:98264 char:13                                                                                                                                                                +             Get-RunspaceData -wait                                                                                                                                                 +             ~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                     + CategoryInfo          : ConnectionError: (Win32_Service: ...?SQLINSTANCE2"):CimInstance) [Write-Error], CimException                                                               + FullyQualifiedErrorId : HRESULT 0x80338012,Get-RunspaceData                                                                                                                                                                                                                                                                                                         Get-RunspaceData : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult   the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command  on the destination to analyze and configure the WinRM service: "winrm quickconfig".                                                                                                  At line:98264 char:13                                                                                                                                                                +             Get-RunspaceData -wait                                                                                                                                                 +             ~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                     + CategoryInfo          : ConnectionError: (Win32_Service: ...?SQLINSTANCE2"):CimInstance) [Write-Error], CimException                                                               + FullyQualifiedErrorId : HRESULT 0x80338012,Get-RunspaceData

Get-RunspaceData : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult
the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command
on the destination to analyze and configure the WinRM service: "winrm quickconfig".
At line:98264 char:13
+             Get-RunspaceData -wait
+             ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ConnectionError: (Win32_Service: ...?SQLINSTANCE2"):CimInstance) [Write-Error], CimException
    + FullyQualifiedErrorId : HRESULT 0x80338012,Get-RunspaceData

Get-RunspaceData : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult
the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command
on the destination to analyze and configure the WinRM service: "winrm quickconfig".
At line:98264 char:13
+             Get-RunspaceData -wait
+             ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ConnectionError: (Win32_Service: ...?SQLINSTANCE2"):CimInstance) [Write-Error], CimException
    + FullyQualifiedErrorId : HRESULT 0x80338012,Get-RunspaceData



ComputerName  : SQL2022
InstanceName  : SQLInstance2
SqlInstance   : SQL2022\SQLInstance2
Changes       : {Changed TcpPort for IPAll to 14338}
RestartNeeded : True
Restarted     : True

When using pwsh (7.5.2):

PS C:\Users\initialAdmin> Set-DbaNetworkConfiguration -SqlInstance SQL2022\SQLInstance2 -StaticPortForIPAll 14339 -RestartService -Confirm:$false
Write-Error:
 Line |
98264 |              Get-RunspaceData -wait
      |              ~~~~~~~~~~~~~~~~~~~~~~
      | The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
Write-Error:
 Line |
98264 |              Get-RunspaceData -wait
      |              ~~~~~~~~~~~~~~~~~~~~~~
      | The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
Write-Error:
 Line |
98264 |              Get-RunspaceData -wait
      |              ~~~~~~~~~~~~~~~~~~~~~~
      | The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
Write-Error:
 Line |
98264 |              Get-RunspaceData -wait
      |              ~~~~~~~~~~~~~~~~~~~~~~
      | The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".

ComputerName  : SQL2022
InstanceName  : SQLInstance2
SqlInstance   : SQL2022\SQLInstance2
Changes       : {Changed TcpPort for IPAll to 14339}
RestartNeeded : True
Restarted     : True

andreasjordan avatar Aug 16 '25 10:08 andreasjordan

This fixes the issue:

PS C:\Users\initialAdmin> 'y' | winrm quickconfig
WinRM service is already running on this machine.
WinRM is not set up to allow remote access to this machine for management.
The following changes must be made:

Create a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.

Make these changes [y/n]?
WinRM has been updated for remote management.

Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.

But I think dbatools should also work on local systems without winrm...

andreasjordan avatar Aug 16 '25 10:08 andreasjordan

This is the script I have used to setu up the maschine: https://github.com/andreasjordan/testing-dbatools/blob/main/setup_azure.ps1

andreasjordan avatar Aug 16 '25 15:08 andreasjordan

@FriedrichWeinmann - Can you help here?

andreasjordan avatar Aug 16 '25 15:08 andreasjordan

Not this week, but I've put it on my pile for next week, when I'm less busy transporting kids to theme parks (the tragic burden of Unclehood. Having to make the ultimate sacrifice and visit theme parks ;) ). Just for clarification: This is all running from an elevated console against localhost, right? On a computer not yet configured for remoting.

Also, SQL2022 is its native hostname or an additional CNAME added? If you run this first, do you get the same results?

Set-DbaCmConnection -ComputerName SQL2022 -DisabledConnectionTypes CimRM, WMI

FriedrichWeinmann avatar Aug 19 '25 15:08 FriedrichWeinmann

SQL2022 is the one and only Azure VM that my script deploys. I RDP into that maschine.

Will try your suggestion on the next test run.

andreasjordan avatar Aug 19 '25 16:08 andreasjordan

Same result:

Image

andreasjordan avatar Aug 20 '25 10:08 andreasjordan