Exciting News

Hey guys I’ve got some exciting news!! As it turns out you can use powershell to admin your servers.  That’s right!

And to prove it, here’s a nice little script I wrote this morning to change the service acct and passwords on all the boxes I wanted.

Actually, I’m just going to show you the single box version, but you all know how easy it is to turn this into a multi-box script.  Here it’s the method that’s important.

I’ll show you 2 ways to do it and I think they’re both equal really.  It just depends on your preference.

$service = gwmi win32_service –filter “name=’MSDTC’”
$service | %{$_.Change($null,$null,$null,$null,$null,$null,”NewUserAcct”, “NewPassword”)}

Here’s a screenshot of the same code.

image

That’s it.  That’s all you need to change the user acct and password for a service.  But we’ve still got a few things to talk about so you understand everything that’s happening here.

  1. If you want to use this against a remote box, then just use the –computername parameter.
  2. Notice I used the –filter param also.  This filters the results on the server itself so you don’t pass all the services across the wire and then filter them.  That method would look like this: > $service = gwmi win32_service | ?{$_.Name –eq “MSDTC”}
  3. The Change() method takes a fixed number of params so you have to put in all the params at least as placeholders.  That’s why all the $null values are in there.
  4. I’ve seen other methods for doing this where they name the params and don’t actually pass in all of them physically, but I haven’t had any luck with these.
  5. Here’s a site that explains all the other parms and the error codes you can get when using this method.  http://www.scriptinternals.de/new/us/Support/Internal/WMI_Win32_Service_Change.htm

Ok, I know I promised you 2 ways to do this but I’m out of time so this one will have to do.  The other one uses the same method, it’s just a different way to script it so you’re not really losing anything.

2 thoughts on “Exciting News”

  1. Dude.. This gets so complicated to accomplish on a cluster with multiple instances on it.

    For eg.. One of the many cluster setups we have is a 5 node cluster but have a total of 7 instances.

    So to change the password on clusters, I have to go through every node and change passwords for all the 7 instance startup accounts.

    and if you are using the same script for standalone and multi-instance clusters… then the Get-wmiobject looks like…..

    Get-wmiobject win32_service -computer $InstanceName -filter “Name LIKE ‘SQLAgent%’ OR Name LIKE ‘MSSQL$%’ OR Name like ‘MSSQLServer’ or Name like ‘SQLSERVERAGENT'” | select name

    I will repost once I finish this script for others to use.

Comments are closed.