Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to handle restarting RS service with alternate credential #229

Merged
merged 1 commit into from
May 16, 2019

Conversation

pshamus
Copy link

@pshamus pshamus commented May 10, 2019

Fixes #228 .

Changes proposed in this pull request:

  • Added code to handle restarting RS service with alternate credential by using Get-WmiObject

How to test this code:
Assuming that adminuser user has access to the computer SSRS and the user running the command does not:

Restore-RSEncryptionKey -KeyPath 'C:\MyFolder\MyKeyFile.snk' -Password 'MyPass' -ComputerName SSRS -Credential (Get-Credential adminuser)

Has been tested on (remove any that don't apply):

  • Powershell 5.1
  • Windows 10
  • SQL Server 2016

do {
$service = Get-WmiObject @getServiceParams
Start-Sleep -Seconds 1
} until ($service.State -eq 'Stopped')
Copy link
Member

Choose a reason for hiding this comment

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

I would do a timeout or number of retries , otherwise it had a change to get stuck here in a infinite loop if the service don't stop

Copy link
Author

Choose a reason for hiding this comment

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

Good idea, I considered that. However, in the current implementation WaitForStatus will wait indefinitely, so I was just mimicking the same behavior.

$service.WaitForStatus([System.ServiceProcess.ServiceControllerStatus]::Stopped)

What do you think is a reasonable amount of time/retries?

Copy link
Member

Choose a reason for hiding this comment

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

I would think a couple of minutes (120 retries) should be good enough


In reply to: 282992334 [](ancestors = 282992334)

@jtarquino jtarquino merged commit 2aca66e into microsoft:master May 16, 2019
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.

Restore-RSEncryptionKey failing when credential is used
2 participants