{"id":303,"date":"2007-09-05T00:00:00","date_gmt":"2007-09-03T00:00:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/changing-service-credentials\/"},"modified":"2021-08-24T13:40:42","modified_gmt":"2021-08-24T13:40:42","slug":"changing-service-credentials","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/database-administration-sql-server\/changing-service-credentials\/","title":{"rendered":"Changing Service Credentials"},"content":{"rendered":"<p class=\"MsoNormal\"><em>or<br \/><\/em><strong>Service Accounts for Something<\/strong><\/p>\n<p class=\"MsoNormal\"><strong>Changing SQL Service Credentials and Restarting with T-SQL<\/strong><\/p>\n<\/p>\n<p>It could be that one is speaking hypothetically, as DBAs so often do, and do so well; but it may be that one is responding to a true-to-life emergency change in a Daliesque paranoiac frenzy, but there could easily come a time when you will need to change those service credentials under which your SQL Server services normally run so happily, day in and day out. <\/p>\n<p>The reasons for changing service credentials are obvious, but must be stated in bullet form for therapeutic reasons so that other DBAs, who may find themselves in the same situation as I am, can plead anonymity. I will take the heat for you:<\/p>\n<\/p>\n<ul>\n<li>Some DBAs often hop from one company to another.  <\/li>\n<li>There are times when DBAs know the password for the service credentials that run SQL Services  <\/li>\n<li>There are myriad services on a plentitude of servers that all use the same account.  <\/li>\n<li>Sometimes DBAs actually login to servers via RDP with this service password  <\/li>\n<li>Active Directory administrators do not always set a specific group policy to prevent account lockouts for the service accounts for SQL Services<\/li>\n<\/ul>\n<p>Remember those surveys that you fill out when you want to download new\/free\/trial software that ask &#8220;How many SQL Servers do you have in your organization?&#8221; If you answer 1-5, you are ok because you have time on your side. You can change the service accounts when a DBA leaves, assuming that with 5 servers you even have a position of &#8220;DBA&#8221;. In this case, you ARE the DBA and network admin and mail administrator and&#8230;However, if you answered 100-500 on the survey it may be time to consider the automation of your management of service accounts, using some simple T-SQL code and some common command line tools.<\/p>\n<p>Before I dive headlong into long strings of code that makes the task of changing service credentials for SQL Services semi-automated, I should post a disclaimer:<\/p>\n<div>\n<p><i>What I am going to present should be tried in QA or test environments thoroughly and for managing those 100-500 systems I would encourage using this query with SQL Server Integration Services instead of linked servers with distributed queries.<\/i> <\/p>\n<\/div>\n<p>My partiality to SSIS and aversion to linked servers would be the only reason for the recommendation. For those interested, I have written several articles on using variables and expressions with SSIS to dynamically control connection strings. But that is a topic for the future.<\/p>\n<p>I use four commands (five, if you count <b>SQLCMD<\/b> which I don&#8217;t) to programmatically control (via T-SQL) the reporting, modification and restarting of SQL Services. I know there are many other ways, using SMO or DMO; but I have not made the leap to being a developer and up until recently pronounced C# as C &#8220;Pound&#8221;. &#8216;Recently&#8217; was about 4 years ago -I am not that naive, but I&#8217;m sure that you get my point.<\/p>\n<p>The four commands are:<\/p>\n<ul>\n<li>Xp_CmdShell (SQL)  <\/li>\n<li>WMIC (Windows)  <\/li>\n<li>SC.EXE (Windows)  <\/li>\n<li>Net Stop and Net Start<\/li>\n<\/ul>\n<p>The T-SQL code that incorporates each command is straightforward. In an effort to adhere to Simple-Talk&#8217;s motto &#8211; SIMPLE &#8211; I should outline the logic before giving a full listing. The goals for the code are:<\/p>\n<ol>\n<li>Display a report of all service account credentials for any SQL-related service. This could include <b>MSSQLServerADHelper<\/b> or <b>SQLBrowser<\/b> as well as the database engine itself (<b>MSSQLSERVER<\/b>) and the SQL Server Agent (<b>SQLSERVERAGENT<\/b>).  <\/li>\n<li>Display only the primary SQL service credentials. I have included the database engine, the agent and the SQL Backup Agent, which is a Red Gate service.  <\/li>\n<li>Display only services that run under an account value that I can specify.  <\/li>\n<li>Change the account information (account name and password) for the primary services.  <\/li>\n<li>Change just password for the primary service accounts.  <\/li>\n<li>Restart the services.<\/li>\n<\/ol>\n<p>This type of logic is easily coded and can appear redundant when looking at the full code with varying options. I should also note that I would generally produce a parameterized stored procedure to handle the input criteria to control the flow of the logic in the query. Since, my goal is to roll this ad-hoc query into SSIS, I chose not to use a stored procedure as this would require creating it on each server I would run the code against. For the time being I am comfortable with an ad-hoc query.<\/p>\n<p>Let&#8217;s begin by looking at each piece of the T-SQL code, the first being the nine parameters that control the flow and set the credential values.<\/p>\n<div class=\"figure\">Figure 1<\/p>\n<pre class=\"theme:ssms2012 lang:tsql\">DECLARE&#160;@Acct&#160;VARCHAR(30)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Lookup&#160;Account&#160;Variable&#160;-&#160;Used&#160;for&#160;Reporting&#160;on&#160;Specific&#160;Accounts. \nDECLARE&#160;@Primary_SQL&#160;SMALLINT&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Work&#160;with&#160;only&#160;the&#160;three&#160;main&#160;services&#160;(Engine,&#160;Agent&#160;and&#160;Red&#160;Gate&#160;SQL&#160;Backup) \nDECLARE&#160;@Service_Name&#160;VARCHAR(100)&#160;&#160;&#160; \n--&#160;Used&#160;to&#160;load&#160;service&#160;cursor \nDECLARE&#160;@Change&#160;SMALLINT&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Used&#160;as&#160;Boolean&#160;to&#160;trigger&#160;a&#160;change&#160;of&#160;the&#160;account&#160;or&#160;password&#160;or&#160;both \nDECLARE&#160;@TSQL&#160;VARCHAR(500)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Used&#160;to&#160;execute&#160;the&#160;T-SQL&#160;Code \nDECLARE&#160;@NEW_Acct&#160;VARCHAR(40)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Sets&#160;the&#160;new&#160;account&#160;for&#160;the&#160;Primary&#160;Services \nDECLARE&#160;@PWD&#160;VARCHAR(50)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Sets&#160;the&#160;new&#160;password&#160;for&#160;the&#160;Primary&#160;Services \nDECLARE&#160;@Restart&#160;SMALLINT&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Used&#160;as&#160;Boolean&#160;to&#160;restart&#160;after&#160;changes \nDECLARE&#160;@Change_PWD_Only&#160;SMALLINT&#160;&#160;&#160;&#160; \n--&#160;Used&#160;as&#160;Boolean&#160;to&#160;Change&#160;the&#160;password&#160;only.&#160; \n<\/pre>\n<\/div>\n<p>These nine parameters, documented in code, are set with values prior to executing the T-SQL code. As I&#8217;m a DBA of a large organization, my first objective was to programmatically change the service account password when necessary. I have added other features that may be of use; such as simply reporting the service credentials for all SQL services, reporting only for a specified account, or changing the service credentials (account and password or both) for the primary services. I chose to allow service credential changes only for primary services, because the triad (Engine, Agent and Red Gate) are the ones that I know run under specific service credentials. This may not be the case for you and your organization, so modification is expected and encouraged, especially when we get to restarting these services. As we walk through the code, the parameter values will become evident. It is enough for the time being to be aware that the only combination of parameters that will cause a restart would be @Change, @Restart and @Primary_SQL all with a value of 1. When any of these parameters are set to 0 the query will only report on or modify the service credentials. Figure 2 shows sample values.<\/p>\n<div class=\"figure\">Figure 2<\/p>\n<pre class=\"theme:ssms2012 lang:tsql\">SET&#160;@NEW_Acct&#160;=&#160;'.\\LocalSystem' \nSET&#160;@PWD&#160;=&#160;'' \nSET&#160;@Change&#160;=&#160;0 \nSET&#160;@Primary_SQL&#160;=&#160;0 \nSET&#160;@Acct&#160;=&#160;NULL \nSET&#160;@Restart&#160;=&#160;0 \nSET&#160;@Change_PWD_Only&#160;=&#160;0 \n<\/pre>\n<\/div>\n<p>After setting the combination of parameters, we can begin to break apart the three commands that drive the query, starting with xp_cmdshell. As most of us know, xp_cmdhsell is an extended stored procedure that allows us DBAs to run OS level commands as if we were in a CMD window. By default, xp_cmdshell is not enabled on SQL 2005 for good reason. We will have enable it as part of the query for SQL Server 2005. In SQL 2000, xp_cmdshell is not a configuration and is on by default for system administrators. The code to enable xp_cmdshell for SQL Server 2005 at the start of the query, in Listing 1.<\/p>\n<div class=\"figure\">Listing 1<\/p>\n<pre class=\"theme:ssms2012 lang:tsql\">EXEC&#160;sp_configure&#160;'show&#160;advanced&#160;options',&#160;1 \nGO \nRECONFIGURE \nGO \nEXEC&#160;sp_configure&#160;'xp_cmdshell',&#160;1 \nGO \nRECONFIGURE&#160;WITH&#160;OVERRIDE \nGO \n<\/pre>\n<\/div>\n<p>So what are we going to use xp_cmdshell for? We are going to populate a temp table with output from the second command, WMIC. WMI, which stands for &#8216;Windows Management Instrumentation&#8217;, is a framework for monitoring and managing many aspects of Windows and the hardware on which it runs, such as disk subsystems, CPU, memory, and for our use, services. WMIC is a command line tool that taps into WMI. We will use WMCI to populate the table with service information specific to SQL services. The code to create the temp table is in Listing 2. The output of the WMIC command will be inserted as one big string, into the column ironically named Big_String.<\/p>\n<div class=\"figure\">Listing 2<\/p>\n<pre class=\"theme:ssms2012 lang:tsql\">IF&#160;EXISTS&#160;(&#160;SELECT&#160;&#160;Name \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;tempdb..sysobjects \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;name&#160;LIKE&#160;'#MyTempTable%'&#160;)&#160; \n&#160;&#160;&#160;&#160;DROP&#160;TABLE&#160;#MyTempTable \n\nCREATE&#160;TABLE&#160;#MyTempTable \n&#160;&#160;&#160;&#160;( \n&#160;&#160;&#160;&#160;&#160;&#160;Big_String&#160;NVARCHAR(500) \n&#160;&#160;&#160;&#160;) \n<\/pre>\n<\/div>\n<p>The code to execute the xp_cmdshell WMIC command, looking for SQL services only, is in Listing 3. Notice that the WMIC command is piped into another command line tool (I know I said only four) called <b>findstr<\/b>. <b>findstr<\/b> is similar to &#8216;grep&#8217; on UNIX system and searches for matching text patterns. In this case we are looking through the WMIC output for the string &#8220;SQL&#8221;.<\/p>\n<p>Listing 3.<\/p>\n<div class=\"figure\">Listing 3.<\/p>\n<pre class=\"theme:ssms2012 lang:tsql\">INSERT&#160;&#160;INTO&#160;#MyTempTable \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;EXEC&#160;master..xp_cmdshell&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'WMIC&#160;SERVICE&#160;GET&#160;Name,StartName&#160;|&#160;findstr&#160;\/I&#160;\"SQL\"' <\/pre>\n<\/div>\n<p>The output of this command is indeed one long string. With some basic text maniuplation, however, we can clean up the out put and feed it into the remainder of the code which uses the parameters to control the flow adhering to the goals of reporting on and modifying the service accounts.<\/p>\n<p>I use several string functions to display the results into formatted output such as Substring(), charindex() and len(). The same code to generate the reports are repeated with IF&#8230;BEGIN&#8230;END clauses based again on the parameter values. For example if @Primary_SQL = 1 and @Acct is NULL the code only shows the three primary services mentioned previously, Engine, Agent and Red Gate SQL Backup, see Listing 4.<\/p>\n<div class=\"figure\">Listing 4<\/p>\n<pre class=\"theme:ssms2012 lang:tsql\">--Show&#160;only&#160;Top&#160;3&#160;SQL&#160;Services&#160;\"Engine,&#160;Agent&#160;and&#160;RedGate&#160;SQL&#160;Backup\"&#160; \n\nIF&#160;@Primary_SQL&#160;=&#160;1 \n&#160;&#160;&#160;&#160;AND&#160;@Acct&#160;IS&#160;NULL&#160; \n&#160;&#160;&#160;&#160;BEGIN \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SELECT&#160;&#160;@@ServerName&#160;AS&#160;ServerName, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RTRIM(LEFT(Big_String,&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;AS&#160;Service_Name, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RTRIM(LTRIM(RTRIM(SUBSTRING(Big_String, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String), \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;LEN(Big_String)))))&#160;AS&#160;Service_Account \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#MyTempTable \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Big_String&#160;IS&#160;NOT&#160;NULL \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;AND&#160;RTRIM(LEFT(Big_String,&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;IN&#160;( \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;'MSSQLSERVER',&#160;'SQLSERVERAGENT',&#160;'SQLBackupAgent'&#160;) \n&#160;&#160;&#160;&#160;END \n<\/pre>\n<\/div>\n<p>Notice I also use the @@Servername value to add in the server on which the code is being run. For global changes executed via linked servers or Integration Services packages, this is useful. The code follows logic to report similarly on non-primary SQL services, such as SQL Browser, and also for specific accounts. By adding a value to the @Acct value, for example, &#8216;.\\LocalSystem&#8217; the code only returns records for services that run under that account. Figure 3 shows the ouptut of a sample report using all services, so a @Primary_SQL value of 0 and @Acct value of NULL.<\/p>\n<p>Figure 3<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/imported\/431-Image3.gif\" alt=\"431-Image3.gif\" \/><\/p>\n<p>After the reporting iterations, comes the actual modifications and restarting of the primary SQL services if the parameter values that control modifications are set correctly. The parameters that control this modification logic are combinations of the following:<\/p>\n<p>@Primary_SQL<br \/>@Change<br \/>@NEW_Acct<br \/>@PWD<br \/>@Restart<br \/>@Change_PWD_Only <\/p>\n<p>Knowing that the code will only ever change the primary services, @Primary_SQL will always need to be set to a value of 1 for any modifications of the services. If not set to 1, the code will be used for reporting only. @Change is another variable that must be set to a value of 1 for any modification to be made. This is a secondary safeguard because this query has, by its very nature, some ominous potential. Time for another disclaimer? @New_Acct is used to set the new account if necessary and @PWD is the new password that goes with the new account. It is possible, as you will see to change the password only without changing the account, hence the @Change_PWD_Only variable. And finally, the almighty @Restart variable. For fear of stating the obvious, @Restart will indeed, like in the film <u>Flatline<\/u>, kill and then resucitate the primary SQL services with its new guardian angel service account.<\/p>\n<p>Let&#8217;s look now at how the code works with these parameters to control the configuration and restarting of the primary services. This is where the third and fourth commands come into play, &#8220;<b>sc.exe<\/b>&#8221; and &#8220;<b>net stop<\/b>&#8221; and &#8220;<b>net start<\/b>&#8220;.<\/p>\n<p><b>sc.exe<\/b> is a command line utility that controls the services that run on a Windows system. With &#8220;sc&#8221; you can query, modify, start and stop any service on a system. The code uses &#8220;sc&#8221; to change the account or password or both. I chose to use &#8220;net stop&#8221; and &#8220;net start&#8221; instead of &#8220;sc&#8221; to change the configuration as these are more common command line service management tools that administrators are familiar with. Plus I needed them so I could use 4 commands instead of just 3. Good practice. Not &#8220;best&#8221; practice, but it keeps the knife blade skill set honed to a razor sharp edge. <\/p>\n<p>Listing 5 shows a snippet of code that modifes the service credentials to change both the account and password for the primary SQL services.<\/p>\n<div class=\"figure\">Listing 5<\/p>\n<pre class=\"theme:ssms2012 lang:tsql\">IF&#160;@Primary_SQL&#160;=&#160;1 \n&#160;&#160;&#160;&#160;AND&#160;@Change&#160;=&#160;1 \n&#160;&#160;&#160;&#160;AND&#160;@Change_PWD_Only&#160;=&#160;0&#160; \n&#160;&#160;&#160;&#160;BEGIN \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DECLARE&#160;Services&#160;CURSOR \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FOR&#160;SELECT&#160;&#160;RTRIM(LEFT(Big_String,&#160;\nCHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;AS&#160;Service_Name \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#MyTempTable \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Big_String&#160;IS&#160;NOT&#160;NULL \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;AND&#160;RTRIM(LEFT(Big_String, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;IN&#160;( \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;'MSSQLSERVER',&#160;'SQLSERVERAGENT',&#160;'SQLBackupAgent'&#160;) \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;OPEN&#160;Services&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FETCH&#160;NEXT&#160;FROM&#160;Services&#160;INTO&#160;@Service_Name&#160;&#160; \n\n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHILE&#160;(&#160;@@fetch_status&#160;&lt;&gt;&#160;-1&#160;)&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;IF&#160;(&#160;@@fetch_status&#160;=&#160;-2&#160;)&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FETCH&#160;NEXT&#160;FROM&#160;Services&#160;INTO&#160;@Service_Name&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CONTINUE&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SET&#160;@TSQL&#160;=&#160;'EXEC&#160;master..xp_cmdshell&#160;''sc&#160;CONFIG&#160;' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+&#160;@Service_Name&#160;+&#160;'&#160;obj=&#160;'&#160;+&#160;'\"'&#160;+&#160;@NEW_Acct&#160;+&#160;'\"&#160;' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+&#160;'password=&#160;'&#160;+&#160;'\"'&#160;+&#160;@PWD&#160;+&#160;'\"''' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PRINT&#160;@TSQL \n\n--Exec&#160;and&#160;Capture&#160;Command&#160;Ouput \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;INSERT&#160;&#160;INTO&#160;#HoldErrors \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;EXEC&#160;(&#160;@TSQL&#160;)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n&#160;&#160;&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FETCH&#160;NEXT&#160;FROM&#160;Services&#160;INTO&#160;@Service_Name&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END&#160;&#160; \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DEALLOCATE&#160;Services&#160; \n\n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SELECT&#160;TOP&#160;2 \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Error_String \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#HoldErrors \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Error_String&#160;IS&#160;NOT&#160;NULL \n\n&#160;&#160;&#160;&#160;END \n<\/pre>\n<\/div>\n<p>Notice that this code uses the @Change_PWD_Only parameter with a value of 0. The code, therefore, expects that the @PWD parameter will contain a value, even if blank (&#8221;). (When seting an account to run as Local System, the values for @NEW_Acct and @PWD would be &#8220;.\\LocalSystem&#8221; and &#8221; respectively as LocalSystem does not require a password).<\/p>\n<p>Another important part of the code at this point will be the use of the #HoldErrors temp table. This table is used to store the output of the executed T-SQL code, stored in the @TSQL variable. Later, we will interrogate the values in the #HoldErrors table to determine if the changes were successful. There is no point (and it would be ludicrous) restarting services if the configurations were not successful. #HoldErrors will let us know if the changes worked and if we should therefore restart. For output we select the top 2 records simply for reporting purposes.<\/p>\n<p>Similar code drives the changing of the password only. This code checks the @Change_PWD_Only variable and if it is 1, then we execute the &#8220;sc&#8221; command without the &#8220;obj&#8221; option but pass in the new password stored in the @PWD variable.<\/p>\n<p>NOTE: There are a couple of caveats when changing the account information for services. The user will have to exist, otherwise there will be an error and they have to have been given &#8220;Logon as Service&#8221; rights. <\/p>\n<p>Now for the scary part&#8230;.<\/p>\n<p>The code that initiate the restarting of the primary services has the built-in safeguards I mentioned previously plus the error checking of the output of the #HoldErrors table. Listing 6 displays the logic of when the services will be restarted.<\/p>\n<div class=\"figure\">Listing 6<\/p>\n<pre class=\"theme:ssms2012 lang:tsql\">--Restart those primary services after changes\n\nIF @Primary_SQL = 1\n&#160;&#160;&#160; and @Restart = 1\n&#160;&#160;&#160; and @Change = 1 \n&#160;&#160;&#160; BEGIN\n&#160;&#160;&#160;&#160;&#160;&#160;&#160; IF EXISTS ( SELECT Top 1\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Error_String\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; FROM&#160;&#160;&#160; #HoldErrors\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Where&#160;&#160; Error_String is not NULL\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; and ERROR_String like '%FAILED%' ) \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; GOTO End_On_Failure <\/pre>\n<\/div>\n<p>As you can see, the three controlling variable need to be set to 1 and if there were errors in the output of the sc command inserted into #HoldErrors, we will fall out to End_On_Failure and the next bit of code, see Listing 7, that does the dirty work of restarting will not execute.<\/p>\n<div class=\"figure\">Listing 7<\/p>\n<pre class=\"theme:ssms2012 lang:tsql\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SET&#160;@TSQL&#160;=&#160;\n'EXEC&#160;master..xp_cmdshell&#160;''START&#160;c:\\utilities\\ReStart_SQL.CMD''' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PRINT&#160;'INTO&#160;THE&#160;ABYSS&#160;WE&#160;GO....' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PRINT&#160;@TSQL \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;EXEC&#160;(&#160;@TSQL&#160;)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END \n&#160;&#160;&#160;&#160;END <\/pre>\n<\/div>\n<p><\/p>\n<p>If we assume that the changes to the service accounts were made successfully and the parameters are set to restart, the code will shell out to a batch file. By using the term &#8220;shell out&#8221; I mean I then need to spawn the batch file to another process outside of the SQL database engine proper. I do this by using the &#8220;START&#8221; command. Without using &#8220;START&#8221;, the services would not be able to come back up, due to this little thing I like to call a paradox.<\/p>\n<p>I chose to create the batch file manually and place it in a location on each server. I did not do this merely because I am lazy, but because&#8230;yeah, well I am lazy. I know code could be enhanced to create the batch file or, for that matter, build a string and then execute it, but a batch file gives me one advantage: we know that SQL is going to &#8220;join the choir invisible&#8221; after we initiate the restart. In the batch I can, also add a command, which I indeed have done, to send me an email to let me know that the services have come back up. I use sqlcmd and sp_send_dbmail to send the notification that services have resumed. I also add the data via the @Query option of sp_send_dbmail by selecting @@Servername and GetDate(). Listing 8 shows the steps in the batch file, &#8220;C:\\utilities\\Restart_SQL.CMD&#8221;<\/p>\n<p>Listing 8<\/p>\n<p>NET STOP \/Y MSSQLSERVER<br \/>NET STOP SQLBackupAgent<br \/>NET START MSSQLSERVER<br \/>NET START SQLSERVERAGENT<br \/>NET START SQLBackupAgent<br \/>sqlcmd -Q &#8220;msdb..sp_send_dbmail @Profile_name = &#8216;DB_Mail&#8217;,@recipients = &#8216;MyName@MyEmail.com&#8217;, @Subject = &#8216;Restarted&#8217;, @Query = &#8216;Select @@Servername + &#8221; restarted at &#8221;, GetDate()'&#8221;<\/p>\n<p>I know now, after working on this script, that there is always room for enhancement and this may not be for everyone. You&#8217;ll want to get familiar with how this script runs with many different parameter options, maybe even commenting out the restart section and testing in a QA environment where the accounts and passwords can be changed at will and services restarted. I believe I have filled my event log with the frequent restarts on my local laptop while testing. It took a while to get over the fear of execution, so to speak, which is exactly what it would have been if there was an inadvertent run against a production system. I am now confident enough though, to roll this script into an SSIS package, the outcome of which I hope to post here soon.<\/p>\n<p>The full code follows:<\/p>\n<\/p>\n<div class=\"figure\">Full Code<\/p>\n<pre class=\"theme:ssms2012 lang:tsql\">--Turn&#160;on&#160;Cmd_Shell&#160;assuming&#160;it&#160;is&#160;not&#160;on. \nSET&#160;Quoted_Identifier&#160;OFF \nGO \n\nIF&#160;SUBSTRING(CONVERT(VARCHAR(50),&#160;SERVERPROPERTY('ProductVersion')),1,1)&#160;=&#160;'9' \nBEGIN \n&#160;&#160;&#160;EXEC&#160;sp_configure&#160;'show&#160;advanced&#160;options',&#160;1 \n&#160;&#160;&#160; \n&#160;&#160;&#160;RECONFIGURE \n&#160;&#160;&#160; \n&#160;&#160;&#160;EXEC&#160;sp_configure&#160;'xp_cmdshell',&#160;1 \n&#160;&#160;&#160; \n&#160;&#160;&#160;RECONFIGURE&#160;WITH&#160;OVERRIDE \n&#160;&#160;&#160; \nEND \n\n\nDECLARE&#160;@Acct&#160;VARCHAR(30)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Lookup&#160;Account&#160;Variable&#160;-&#160;Used&#160;for&#160;Reporting&#160;on&#160;Specific&#160;Accounts. \nDECLARE&#160;@Primary_SQL&#160;SMALLINT&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Work&#160;with&#160;only&#160;the&#160;three&#160;main&#160;services&#160;(Engine,&#160;Agent&#160;and&#160;Red&#160;Gate&#160;SQL&#160;Backup) \nDECLARE&#160;@Service_Name&#160;VARCHAR(100)&#160;&#160;&#160; \n--&#160;Used&#160;to&#160;load&#160;service&#160;cursor \nDECLARE&#160;@Change&#160;SMALLINT&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Used&#160;as&#160;Boolean&#160;to&#160;trigger&#160;a&#160;change&#160;of&#160;the&#160;account&#160;or&#160;password&#160;or&#160;both \nDECLARE&#160;@TSQL&#160;VARCHAR(500)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Used&#160;to&#160;execute&#160;the&#160;T-SQL&#160;Code \nDECLARE&#160;@NEW_Acct&#160;VARCHAR(40)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Sets&#160;the&#160;new&#160;account&#160;for&#160;the&#160;Primary&#160;Services \nDECLARE&#160;@PWD&#160;VARCHAR(50)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Sets&#160;the&#160;new&#160;password&#160;for&#160;the&#160;Primary&#160;Services \nDECLARE&#160;@Restart&#160;SMALLINT&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n--&#160;Used&#160;as&#160;Boolean&#160;to&#160;restart&#160;after&#160;changes \nDECLARE&#160;@Change_PWD_Only&#160;SMALLINT&#160;&#160;&#160;&#160; \n--&#160;Used&#160;as&#160;Boolean&#160;to&#160;Change&#160;the&#160;password&#160;only.&#160; \n\nSET&#160;@NEW_Acct&#160;=&#160;'.\\LocalSystem' \nSET&#160;@PWD&#160;=&#160;'' \nSET&#160;@Change&#160;=&#160;0 \nSET&#160;@Primary_SQL&#160;=&#160;0 \nSET&#160;@Acct&#160;=&#160;NULL \nSET&#160;@Restart&#160;=&#160;0 \nSET&#160;@Change_PWD_Only&#160;=&#160;0 \n\n\n\nIF&#160;EXISTS&#160;(&#160;SELECT&#160;&#160;Name \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;tempdb..sysobjects \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;name&#160;LIKE&#160;'#MyTempTable%'&#160;)&#160; \n&#160;&#160;&#160;&#160;DROP&#160;TABLE&#160;#MyTempTable \n\nCREATE&#160;TABLE&#160;#MyTempTable \n&#160;&#160;&#160;&#160;( \n&#160;&#160;&#160;&#160;&#160;&#160;Big_String&#160;NVARCHAR(500) \n&#160;&#160;&#160;&#160;) \nINSERT&#160;&#160;INTO&#160;#MyTempTable \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;EXEC&#160;master..xp_cmdshell&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'WMIC&#160;SERVICE&#160;GET&#160;Name,StartName&#160;|&#160;findstr&#160;\/I&#160;\"SQL\"' \n\n\n--Show&#160;only&#160;Top&#160;3&#160;SQL&#160;Services&#160;\"Engine,&#160;Agent&#160;and&#160;RedGate&#160;SQL&#160;Backup\"&#160; \n\nIF&#160;@Primary_SQL&#160;=&#160;1 \n&#160;&#160;&#160;&#160;AND&#160;@Acct&#160;IS&#160;NULL&#160; \n&#160;&#160;&#160;&#160;BEGIN \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SELECT&#160;&#160;@@ServerName&#160;AS&#160;ServerName, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RTRIM(LEFT(Big_String,&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;AS&#160;Service_Name, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RTRIM(LTRIM(RTRIM(SUBSTRING(Big_String,&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String),&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;LEN(Big_String)))))&#160;AS&#160;Service_Account \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#MyTempTable \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Big_String&#160;IS&#160;NOT&#160;NULL&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;AND&#160;RTRIM(LEFT(Big_String,&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;IN&#160;( \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;'MSSQLSERVER',&#160;'SQLSERVERAGENT',&#160;'SQLBackupAgent'&#160;) \n&#160;&#160;&#160;&#160;END \nELSE&#160; \n\n--&#160;Show&#160;only&#160;services&#160;that&#160;match&#160;@acct&#160;value&#160;for&#160;primary&#160;services \n\n&#160;&#160;&#160;&#160;IF&#160;@Primary_SQL&#160;=&#160;1 \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;AND&#160;@Acct&#160;IS&#160;NOT&#160;NULL&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SELECT&#160;&#160;@@ServerName&#160;AS&#160;ServerName, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RTRIM(LEFT(Big_String,&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;AS&#160;Service_Name, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RTRIM(LTRIM(RTRIM(SUBSTRING(Big_String,&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String),&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;LEN(Big_String)))))&#160;AS&#160;Service_Account \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#MyTempTable \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Big_String&#160;IS&#160;NOT&#160;NULL&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AND&#160;RTRIM(LEFT(Big_String,&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;IN&#160;( \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;'MSSQLSERVER',&#160;'SQLSERVERAGENT',&#160;'SQLBackupAgent'&#160;) \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;AND&#160;RTRIM(LTRIM(RTRIM(SUBSTRING(Big_String,&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String),&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;LEN(Big_String)))))&#160;LIKE&#160;'' +&#160;'%'&#160;+&#160;@Acct&#160;+&#160;'%'&#160;+&#160;'' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END \n&#160;&#160;&#160;&#160;ELSE&#160; \n\n--Show&#160;specified&#160;@Acct&#160;for&#160;all&#160;SQL&#160;Services \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;IF&#160;@Primary_SQL&#160;=&#160;0 \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;AND&#160;@Acct&#160;IS&#160;NOT&#160;NULL&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SELECT&#160;&#160;@@ServerName&#160;AS&#160;ServerName, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RTRIM(LEFT(Big_String,&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; AS&#160;Service_Name, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RTRIM(LTRIM(RTRIM(SUBSTRING(Big_String,&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String),&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;LEN(Big_String)))))&#160;AS&#160;Service_Account \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#MyTempTable \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;RTRIM(LTRIM(RTRIM(SUBSTRING(Big_String,&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String),&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;LEN(Big_String)))))&#160;LIKE&#160;''&#160;+&#160;'%'&#160;+&#160;@Acct&#160;+&#160;'%'&#160;+&#160;'' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ELSE&#160; \n\n--Show&#160;all&#160;SQL&#160;Services&#160;and&#160;all&#160;accounts \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;IF&#160;@Primary_SQL&#160;=&#160;0&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN \n\n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SELECT&#160;&#160;@@ServerName&#160;AS&#160;ServerName, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RTRIM(LEFT(Big_String, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;AS&#160;Service_Name, \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;RTRIM(LTRIM(RTRIM(SUBSTRING(Big_String,&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String),&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;LEN(Big_String)))))&#160;AS&#160;Service_Account \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#MyTempTable \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Big_String&#160;IS&#160;NOT&#160;NULL&#160; \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END \n\n--&#160;Create&#160;Table&#160;to&#160;Hold&#160;Errors&#160;for&#160;Service&#160;Restarts \n\nIF&#160;EXISTS&#160;(&#160;SELECT&#160;&#160;Name \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;tempdb..sysobjects \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;name&#160;LIKE&#160;'#HoldErrors%'&#160;)&#160; \n&#160;&#160;&#160;&#160;DROP&#160;TABLE&#160;#HoldErrors \n\nCREATE&#160;TABLE&#160;#HoldErrors \n&#160;&#160;&#160;&#160;( \n&#160;&#160;&#160;&#160;&#160;&#160;Error_String&#160;NVARCHAR(1000) \n&#160;&#160;&#160;&#160;) \n\n--&#160;Change&#160;Account&#160;and&#160;Password \n\nIF&#160;@Primary_SQL&#160;=&#160;1 \n&#160;&#160;&#160;&#160;AND&#160;@Change&#160;=&#160;1 \n&#160;&#160;&#160;&#160;AND&#160;@Change_PWD_Only&#160;=&#160;0&#160; \n&#160;&#160;&#160;&#160;BEGIN \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DECLARE&#160;Services&#160;CURSOR \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FOR&#160;SELECT&#160;&#160;RTRIM(LEFT(Big_String,&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;AS&#160;Service_Name \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#MyTempTable \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Big_String&#160;IS&#160;NOT&#160;NULL&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;AND&#160;RTRIM(LEFT(Big_String,&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;IN&#160;( \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;'MSSQLSERVER',&#160;'SQLSERVERAGENT',&#160;'SQLBackupAgent'&#160;) \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;OPEN&#160;Services&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FETCH&#160;NEXT&#160;FROM&#160;Services&#160;INTO&#160;@Service_Name&#160;&#160; \n\n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHILE&#160;(&#160;@@fetch_status&#160;&lt;&gt;&#160;-1&#160;)&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;IF&#160;(&#160;@@fetch_status&#160;=&#160;-2&#160;)&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FETCH&#160;NEXT&#160;FROM&#160;Services&#160;INTO&#160;@Service_Name&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CONTINUE&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SET&#160;@TSQL&#160;=&#160;'EXEC&#160;master..xp_cmdshell&#160;''sc&#160;CONFIG&#160;' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+&#160;@Service_Name&#160;+&#160;'&#160;obj=&#160;'&#160;+&#160;'\"'&#160;+&#160;@NEW_Acct&#160;+&#160;'\"&#160;' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+&#160;'password=&#160;'&#160;+&#160;'\"'&#160;+&#160;@PWD&#160;+&#160;'\"''' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PRINT&#160;@TSQL \n\n--Exec&#160;and&#160;Capture&#160;Command&#160;Ouput \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;INSERT&#160;&#160;INTO&#160;#HoldErrors \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;EXEC&#160;(&#160;@TSQL&#160;)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n&#160;&#160;&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FETCH&#160;NEXT&#160;FROM&#160;Services&#160;INTO&#160;@Service_Name&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END&#160;&#160; \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DEALLOCATE&#160;Services&#160; \n\n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SELECT&#160;TOP&#160;2 \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Error_String \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#HoldErrors \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Error_String&#160;IS&#160;NOT&#160;NULL \n\n&#160;&#160;&#160;&#160;END \nELSE \n--Change&#160;Password&#160;Only \n\nIF&#160;@Primary_SQL&#160;=&#160;1 \n&#160;&#160;&#160;&#160;AND&#160;@Change&#160;=&#160;1 \n&#160;&#160;&#160;&#160;AND&#160;@Change_PWD_Only&#160;=&#160;1&#160; \n&#160;&#160;&#160;&#160;BEGIN \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DECLARE&#160;Services&#160;CURSOR \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FOR&#160;SELECT&#160;&#160;RTRIM(LEFT(Big_String,&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;AS&#160;Service_Name \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#MyTempTable \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Big_String&#160;IS&#160;NOT&#160;NULL \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;AND&#160;RTRIM(LEFT(Big_String,&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CHARINDEX('&#160;&#160;&#160;&#160;&#160;',&#160;Big_String)))&#160;IN&#160;( \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;'MSSQLSERVER',&#160;'SQLSERVERAGENT',&#160;'SQLBackupAgent'&#160;) \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;OPEN&#160;Services&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FETCH&#160;NEXT&#160;FROM&#160;Services&#160;INTO&#160;@Service_Name&#160;&#160; \n\n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHILE&#160;(&#160;@@fetch_status&#160;&lt;&gt;&#160;-1&#160;)&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;IF&#160;(&#160;@@fetch_status&#160;=&#160;-2&#160;)&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FETCH&#160;NEXT&#160;FROM&#160;Services&#160;INTO&#160;@Service_Name&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;CONTINUE&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SET&#160;@TSQL&#160;=&#160;'EXEC&#160;master..xp_cmdshell&#160;''sc&#160;CONFIG&#160;' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+&#160;@Service_Name&#160;+&#160;'&#160;password=&#160;'&#160;+&#160;'\"'&#160;+&#160;@PWD&#160;+&#160;'\"''' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PRINT&#160;@TSQL \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;INSERT&#160;&#160;INTO&#160;#HoldErrors \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;EXEC&#160;(&#160;@TSQL&#160;)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n&#160;&#160;&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FETCH&#160;NEXT&#160;FROM&#160;Services&#160;INTO&#160;@Service_Name&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END&#160;&#160; \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;DEALLOCATE&#160;Services&#160; \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SELECT&#160;TOP&#160;2 \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Error_String \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#HoldErrors \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Error_String&#160;IS&#160;NOT&#160;NULL \n\n&#160;&#160;&#160;&#160;END \n\n&#160; \n\n--Restart&#160;those&#160;primary&#160;services&#160;after&#160;changes \n\nIF&#160;@Primary_SQL&#160;=&#160;1 \n&#160;&#160;&#160;&#160;AND&#160;@Restart&#160;=&#160;1 \n&#160;&#160;&#160;&#160;AND&#160;@Change&#160;=&#160;1&#160; \n&#160;&#160;&#160;&#160;BEGIN \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;IF&#160;EXISTS&#160;(&#160;SELECT&#160;TOP&#160;1 \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Error_String \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;FROM&#160;&#160;&#160;&#160;#HoldErrors \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;WHERE&#160;&#160;&#160;Error_String&#160;IS&#160;NOT&#160;NULL \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;AND&#160;ERROR_String&#160;LIKE&#160;'%FAILED%'&#160;)&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;GOTO&#160;End_On_Failure \n\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;BEGIN \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;SET&#160;@TSQL&#160;=&#160;\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 'EXEC&#160;master..xp_cmdshell&#160;''START&#160;c:\\utilities\\ReStart_SQL.CMD''' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PRINT&#160;'INTO&#160;THE&#160;ABYSS&#160;WE&#160;GO....' \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PRINT&#160;@TSQL \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;EXEC&#160;(&#160;@TSQL&#160;)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;END \n&#160;&#160;&#160;&#160;END \n\n\nEnd_On_Failure: \nPRINT&#160;'Did&#160;not&#160;Restart' \n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>One day, you may need to change those service credentials under which your SQL Server services normally run. If you have a number of servers, then you&#8217;ll really want to read about Rodney&#8217;s solution.&hellip;<\/p>\n","protected":false},"author":221800,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143527],"tags":[4170,4818,4150,4151],"coauthors":[],"class_list":["post-303","post","type-post","status-publish","format-standard","hentry","category-database-administration-sql-server","tag-database-administration","tag-service-account-credentials-sql-server-tsql-system-admin","tag-sql","tag-sql-server"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/221800"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=303"}],"version-history":[{"count":5,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/303\/revisions"}],"predecessor-version":[{"id":92284,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/303\/revisions\/92284"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=303"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}