dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Restart-DbaService not working well with Credentials

Open dokier opened this issue 11 months ago • 4 comments

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

Restart-DbaService does not work well when passing a Credential.

WARNING: [12:44:52][Get-DbaCmObject] [servername.domain.com] Invalid connection credentials

Restart-DbaService calls Update-ServiceStatus but it's not passing a credential on line 151 and 157. Even if you add a Credential here, Update-ServiceStatus then uses Invoke-Parallel calling a script block called "$svcControlBlock" but there is no credential being passed there either.

if ($processArray) {
            if ($PSCmdlet.ShouldProcess("$ProcessArray", "Restarting Service")) {
                $services = Update-ServiceStatus -InputObject $processArray -Action 'stop' -Timeout $Timeout -EnableException $EnableException
                foreach ($service in ($services | Where-Object { $_.Status -eq 'Failed' })) {
                    $service
                }
                $services = $services | Where-Object { $_.Status -eq 'Successful' }
                if ($services) {
                    Update-ServiceStatus -InputObject $services -Action 'restart' -Timeout $Timeout -EnableException $EnableException
                }
            }
        } else {
            Stop-Function -EnableException $EnableException -Message "No SQL Server services found with current parameters."
        }

Steps to Reproduce

# provide your command(s) executed pertaining to dbatools
# please include variable values (redacted or fake if needed) for reference

Log into your client computer with an account without access to the remote server (this step is very important). Then create a credential variable with an account with access to the remote server. $cred = Get-Credential # Enter a credential to access to the remote server" Restart-DbaService -ComputerName computer1 -Credential $cred

Please confirm that you are running the most recent version of dbatools

2.1.28

Other details or mentions

No response

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.17763.6414
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.6414
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Not Important here

.NET Framework Version

.NET Framework 4.8.4762.0

dokier avatar Nov 21 '24 16:11 dokier