Use PowerShell to change service accounts through SQL Configuration Manager

Works with SQL 2008 R2. I use PowerShell to update the Service Accounts for the SQL Server, Agent, and Analysis Server:

$servername = "ServerName";

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | out-null

$SMOWmiserver = New-Object ('Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer') $servername;

$servicename = "MSSQLSERVER";

//SQLSERVERAGENT
// MSSQLServerOLAPService

$ChangeService=$SMOWmiserver.Services | where {$_.name -eq $servicename};

$username = "UserName";
$password = "Password";

$ChangeService.SetServiceAccount($username, $password);

Leave a Reply