-
Book Overview & Buying
-
Table Of Contents
SQL Server 2014 with Powershell v5 Cookbook
By :
We will see how to change SQL Server accounts in this recipe.
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.
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 new Wmi.ManagedComputer object as follows:
#import SQL Server module Import-Module SQLPS -DisableNameChecking #default SQL Server instance $instanceName = "localhost" $managedComputer = New-Object -TypeName Microsoft.SqlServer.Management.Smo...