Changing SQL Server service account
We will see how to change SQL Server accounts in this recipe.
Getting ready
For this recipe, you will need to create another Windows/Domain
account that you can use to change the service account to.
In this recipe, we will change the service account for SQLSERVERAGENT
from QUERYWORKS\sqlservice
to QUERYWORKS\sqlagent
, which are available in the Virtual Machine (VM) created in Appendix B, Creating a SQL Server VM if you've created the same VM. If you are using a different environment, you must substitute these with accounts that already exist in your system.
How to do it...
Let's explore the code required to change a SQL Server service account:
- Open PowerShell ISE as an administrator.
- Import the
SQLPS
module and create a newWmi.ManagedComputer
object as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking #default SQL Server instance $instanceName = "localhost" $managedComputer = New-Object -TypeName Microsoft.SqlServer...