Change SQL Server Service Accounts with Powershell

  • Comments posted to this topic are about the item Change SQL Server Service Accounts with Powershell

  • Why stop and start the services to change the password?

  • I just tested it on my 2014 box several times and took out the stop and start of the service and the account was changed however, it caused some issues and the Agent will not come online.

    This is what I had always gone by

    From MSDN.. https://msdn.microsoft.com/en-us/library/ms345578.aspx

    When you change the service startup account for the Database Engine and SQL Server Agent, the SQL Server service (the Database Engine) must be restarted for the change to take effect. When the service is restarted, all databases associated with that instance of SQL Server will be unavailable until the service successfully restarts. If you have to change the service startup account of SQL Server or SQL Server Agent, make sure that you do so during regularly scheduled maintenance or when the databases can be taken offline without interrupting daily operations.

  • thedspaincrew (2/24/2016)


    I just tested it on my 2014 box several times and took out the stop and start of the service and the account was changed however, it caused some issues and the Agent will not come online.

    This is what I had always gone by

    From MSDN.. https://msdn.microsoft.com/en-us/library/ms345578.aspx

    When you change the service startup account for the Database Engine and SQL Server Agent, the SQL Server service (the Database Engine) must be restarted for the change to take effect. When the service is restarted, all databases associated with that instance of SQL Server will be unavailable until the service successfully restarts. If you have to change the service startup account of SQL Server or SQL Server Agent, make sure that you do so during regularly scheduled maintenance or when the databases can be taken offline without interrupting daily operations.

    That is when you change the account, not the password.

  • This script changes both the account and password.

  • thedspaincrew (2/24/2016)


    This script changes both the account and password.

    Ahhhh, My apologies. It would help if I actually read through the entire script.

  • No worries. Thanks for taking the time to check it out.

    Michael

  • It's a great script, I like it. I hardly ever change the account but I change the service passwords every 30 days.

  • Thanks for the script.

  • right on. thanks for checking it out.

    Michael

  • Hi,

    thanks for sharing.

    While I was reading the script, I've noticed a little display bug:

    if($changestatus.returnvalue -eq 0)

    {

    write-host $server'......service change successfull' -BackgroundColor Blue -ForegroundColor White

    }

    if($changestatus.returnvalue -gt 0) ##if fails see what the return value is. this link describes the return values https://msdn.microsoft.com/en-us/library/windows/desktop/aa393660(v=vs.85).aspx

    {

    write-host $server'......service change successfull' -BackgroundColor red -ForegroundColor yellow

    }

    The same goes for SQL Agent message when the change fails.

    Regards.

  • thanks i will take a look at that

    Michael

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply