< Back

Update-DbaServiceAccount

Mon Jan 13, 2020 6:20 pm

NAME Update-DbaServiceAccount



SYNOPSIS

Changes service account (or just its password) of the SQL Server service.





SYNTAX

Update-DbaServiceAccount [-ComputerName <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>] [-Credential

<Pscredential>] [-ServiceName] <System.String[]> [-Username <String>] [-ServiceCredential <Pscredential>]

[-PreviousPassword <Securestring>] [-SecurePassword <Securestring>] [-EnableException <Switch>]

[<CommonParameters>]



Update-DbaServiceAccount [-Credential <Pscredential>] -InputObject <System.Object[]> [-Username <String>]

[-ServiceCredential <Pscredential>] [-PreviousPassword <Securestring>] [-SecurePassword <Securestring>]

[-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

Reconfigure the service account or update the password of the specified SQL Server service. The service will be

restarted in the event of changing the account.





PARAMETERS

-ComputerName [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Credential [<Pscredential>]

Windows Credential with permission to log on to the server running the SQL instance



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.

This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables

advanced scripting.

Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own

try/catch.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-InputObject [<System.Object[]>]

A collection of services. Basically, any object that has ComputerName and ServiceName properties. Can be piped

from Get-DbaService.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-PreviousPassword [<Securestring>]

An old password of the service account. Optional when run under local admin privileges.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SecurePassword [<Securestring>]

New password of the service account. The function will ask for a password if not specified. MSAs and local

system accounts will ignore the password.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ServiceCredential [<Pscredential>]

Windows Credential object under which the service will be setup to run. Cannot be used with -Username. For

local service accounts use one of the following usernames with empty password:

LOCALSERVICE

NETWORKSERVICE

LOCALSYSTEM



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ServiceName [<System.String[]>]

A name of the service on which the action is performed. E.g. MSSQLSERVER or SqlAgent$INSTANCENAME



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Username [<String>]

Username of the service account. Cannot be used with -ServiceCredential. For local service accounts use one of

the following usernames omitting the -SecurePassword parameter:

LOCALSERVICE

NETWORKSERVICE

LOCALSYSTEM



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: Service, SqlServer, Instance, Connect

Author: Kirill Kravtsov (@nvarscar)



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



Requires Local Admin rights on destination computer(s).



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$SecurePassword = ConvertTo-SecureString 'Qwerty1234' -AsPlainText -Force



Update-DbaServiceAccount -ComputerName sql1 -ServiceName 'MSSQL$MYINSTANCE' -SecurePassword $SecurePassword



Changes the current service account's password of the service MSSQL$MYINSTANCE to 'Qwerty1234'

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>$cred = Get-Credential



PS C:\\> Get-DbaService sql1 -Type Engine,Agent -Instance MYINSTANCE | Update-DbaServiceAccount -ServiceCredential

$cred



Requests credentials from the user and configures them as a service account for the SQL Server engine and agent

services of the instance sql1\\MYINSTANCE

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Update-DbaServiceAccount -ComputerName sql1,sql2 -ServiceName 'MSSQLSERVER','SQLSERVERAGENT' -Username

NETWORKSERVICE



Configures SQL Server engine and agent services on the machines sql1 and sql2 to run under Network Service system

user.

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Get-DbaService sql1 -Type Engine -Instance MSSQLSERVER | Update-DbaServiceAccount -Username

'MyDomain\\sqluser1'



Configures SQL Server engine service on the machine sql1 to run under MyDomain\\sqluser1. Will request user to

input the account password.



RELATED LINKS