Our domain security policy requires us to change our Domain Account passwords every once in a while. This security feature is a good practice but the change of password requires me to change my SQL Server component startup accounts to be changed also as most of them run under my Domain Account.
Tired of accomplishing this task which requires me to type out my user name and password (twice for the reconfirmation 🙂 ) brought forward the need for automating this task. Once I did this, I thought it would be prudent for me to share the same with the SQL community. WMI is quite powerful and a number of tasks can be achieved through it which you shall see in my future blog posts. I have created a category in my blog completely for WMI.
Addition: October 24th, 2011
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.
Download the file: pwdchange file and change the name to pwdchange.vbs. This can be executed from command prompt using the following command (provided you have Windows Script Host which almost all Windows Servers have):
cscript pwdchange.vbs
The script has comments written to help you understand the same. This script makes use of the following namespaces:
\root\Microsoft\SqlServer\ComputerManagement (SQL Server 2005)
\root\CIMV2 (SQL Server 2000)
The reason I do not use SQL Server 2000 WMI namespace as it is not installed by default with a SQL Server 2000 default installation. It has to be installed separately. So, I decided to use CIMV2 which has Win32_Service for achieving the same purpose. In the script you would have to provide the following details:
strAccount1 = “Account1” ‘ For alias@domain.com
strAccount2 = “Account2” ‘ For domain\alias naming convention
strAccount3 = “Account1” ‘ To cover any other naming convention
strAlias = “Alias” ‘ Provide the alias
strDomain = “DomainName” ‘ Provide the domain name
strPassword = “Set Password Here” ‘ Put the new password here
Pingback: WMI Script for changing passwords of SQL Server 2008 instances « Troubleshootingsql's Blog
Changing account and password through WMI leads to a service restart. If you are changing the password only and the service account remains the same, only then a service restart is not required. Refer http://support.microsoft.com/kb/936492 for more information.
LikeLike