Changing SQL Server service account
We will see how to change SQL Server accounts in this recipe.
Getting ready
To perform 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\sqlagent
to QUERYWORKS\sqlagent01
. Feel free to 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 the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module, and create a newWmi.ManagedComputer
object as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking $instanceName = "KERRIGAN" $managedComputer = New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer' -ArgumentList $instanceName
Add the following script and run:
#get handle to service #note we are using...