About these ads

WMI Script for changing passwords of SQL Server 2008 and SQL Server 2012 instances   2 comments


I had previously blogged on how to change the password of SQL Server 2005 and SQL Server 2000 instances using WMI [blog post]. I recently needed to change the passwords of my SQL Server 2008 instances for multiple instances. So, I thought it was high time I modified my script to change the passwords for SQL Server 2008 instances programmatically.

I just updated my script on Tech Net. Here is the link. For SQL Server 2008, I use the namespace:

\root\Microsoft\SqlServer\ComputerManagement10 (SQL Server 2008)

The SQL Server 2012 namespace is: \root\Microsoft\SqlServer\ComputerManagement11 (SQL Server 2012)

All the namespaces can detect lower version services as well till SQL Server 2005. Currently the script provides all the WMI namespaces available till date. You will need to modify the script or add checks in case a namepsace is not present.

If you are using SQL Server 2008 R2, then you need to have this fix applied so that SetServiceAccount can work:

2397020 FIX: “Access is denied. [0x80070005]” error message occurs in SSCM when you try to change the password of an account of SQL Server 2008 R2 in Windows Vista or in a later version of Windows http://support.microsoft.com/default.aspx?scid=kb;EN-US;2397020

If you use SetServiceAccount to change the password, then this will result in a SQL Server service restart. The script provided on the Technet Gallery is for changing both the service account and the password. If only the password needs to be changed for the service account, then use SetServiceAccountPassword. This will change the password and will not automatically restart your SQL Server service.

About these ads

Posted April 8, 2010 by Amit Banerjee in Scripts, WMI

Tagged with ,

2 responses to “WMI Script for changing passwords of SQL Server 2008 and SQL Server 2012 instances

Subscribe to comments with RSS.

  1. I had to add UCase function in the IF condition in order to make it work for SQL 2005 services. May be it’s a good idea to have it in your code so that so one lands up in any issues.

    If(UCase(strStartupAcct) = UCase(strAccount1) OR UCase(strStartupAcct) = UCase(strAccount2) OR UCase(strStartupAcct) = UCase(strAccount3)) Then

  2. I have executed this on multiple servers and it works without having to convert the variables to Upper Case. Is your server using a case sensitive locale?

It is always good to hear from you! :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,316 other followers

%d bloggers like this: