Change Service Account Passwords


  1.    30 Jul 2007 #1
    Buck Woody - Microsoft SQL Server Team Guest

    Change Service Account Passwords


    Is there a way to change a service account password using PowerShell? I have
    a VB Script that will do it, but it's a bit clunky. Thanks!
      My System SpecsSystem Spec

  2.    30 Jul 2007 #2
    IT Staff Guest

    Re: Change Service Account Passwords


    well, show the vb code and we will translate to powershell for you ...in
    shorter forms

    "Buck Woody - Microsoft SQL Server Team"
    <BuckWoodyMicrosoftSQLServerTeam@discussions.microsoft.com> wrote in message
    newsFCA6DAF-F582-416F-B5F2-D08BFAF2E8A7@microsoft.com...
    > Is there a way to change a service account password using PowerShell? I
    > have
    > a VB Script that will do it, but it's a bit clunky. Thanks!



      My System SpecsSystem Spec

  3.    30 Jul 2007 #3
    Buck Woody - Microsoft SQL Server Team Guest

    Re: Change Service Account Passwords


    I'm not sure translating line by line is the best method - I wasn't sure if
    there was a more direct route. At any rate, here's the VB code:
    Set oArgs = WScript.Arguments


    ' Verify the inputs.

    If oArgs.Count <> 5 Then
    WScript.Echo "Usage: ChangeSQLServiceAccounts.vbs MachineName
    InstaNcename ServiceType SQLAccount SQLPassword"
    WScript.Echo "ServiceType = 1 (SQLServer), 2 (Agent), 3
    (FTE), 4 (DTS), 5 (AS), 6 (RS), 7 (Browser)"
    WScript.Echo "Example: ChangeSQLServiceAccounts.vbs .
    MSSQLServer 1 BuiltIn\System NULL"
    WScript.Quit(1)
    Else

    ' Load the inputs into variables.

    strComputer = oArgs(0)
    strInstanceName = oArgs(1)
    strServiceType = oArgs(2)
    strAccountName = oArgs(3)
    strPassword = oArgs(4)
    End If

    ' Get a WMI object for the SQL namespace.

    Set objWMIService = GetObject("winmgmts:" &
    "{impersonationLevel=impersonate}!\\" & strComputer &
    "\ROOT\microsoft\sqlserver\ComputerManagement")

    ' Get an instance for this specific service.

    Set objSQLService = objWMIService.Get("SqlService.ServiceName=""" &
    strInstanceName & """,SQLServiceType=" & strServiceType)

    ' Obtain an InParameters object specific to the SQLService.SetServiceAccount
    method.

    Set objInParam =
    objSQLService.Methods_("SetServiceAccount").inParameters.SpawnInstance_()

    ' Add the input parameters to the input object.

    objInParam.Properties_.item("ServiceStartName") = strAccountName
    objInParam.Properties_.item("ServiceStartPassword") = strPassword

    ' Call the SetServiceAccount method, and pass in the input object.

    Set objOutParams = objSQLService.ExecMethod_("SetServiceAccount", objInParam)

    'Check the return to see whether there were any errors.

    If objOutParams.ReturnValue = 0 Then
    Wscript.Echo "The service account was changed to " & strAccountName
    Else
    Wscript.Echo "Could not change the service account to " & strAccountName
    & " due to error " & objOutParams.ReturnValue
    End If


    "IT Staff" wrote:

    > well, show the vb code and we will translate to powershell for you ...in
    > shorter forms
    >
    > "Buck Woody - Microsoft SQL Server Team"
    > <BuckWoodyMicrosoftSQLServerTeam@discussions.microsoft.com> wrote in message
    > newsFCA6DAF-F582-416F-B5F2-D08BFAF2E8A7@microsoft.com...
    > > Is there a way to change a service account password using PowerShell? I
    > > have
    > > a VB Script that will do it, but it's a bit clunky. Thanks!

    >
    >
    >

      My System SpecsSystem Spec

  4.    31 Jul 2007 #4
    Marco Shaw Guest

    Re: Change Service Account Passwords


    Buck Woody - Microsoft SQL Server Team wrote:
    > Is there a way to change a service account password using PowerShell? I have
    > a VB Script that will do it, but it's a bit clunky. Thanks!


    Whithin this class:
    $class=[WMICLASS]'\\.\root\Microsoft\SqlServer\ComputerManagement:SqlService'

    There's a method named setserviceaccount().

    I've not used WMI enough, especially with methods, to figure out how to
    invoke the method in this case.

    Doing $class.psbase gives me a invokemethod() method, but I've not been
    able to figure out the syntax or whether I'm on the right track.

    Marco
      My System SpecsSystem Spec

  5.    31 Jul 2007 #5
    Buck Woody - Microsoft SQL Server Team Guest

    RE: Change Service Account Passwords


    Answered my own question, thought I'd share the script:

    # Copyright Buck Woody, 2007
    # All scripts provided AS-IS. No functionality is guaranteed in any way.
    # Change Service Account name and password using PowerShell and WMI
    $class = Get-WmiObject -computername "SQLVM03-QF59YPW" -namespace
    root\Microsoft\SqlServer\ComputerManagement -class SqlService
    #This remmed out part shows the services - I'll just go after number 6 (SQL
    Server Agent in my case):
    # foreach ($classname in $class) {write-host $classname.DisplayName}
    # $class[6].DisplayName
    stop-service -displayName $class[6].DisplayName
    # Note: I recommend you make these parameters, so that you don't store
    passwords. At your own risk here!
    $class[6].SetServiceAccount("account", "password")
    start-service -displayName $class[6].DisplayName


    "Buck Woody - Microsoft SQL Server Team" wrote:

    > Is there a way to change a service account password using PowerShell? I have
    > a VB Script that will do it, but it's a bit clunky. Thanks!

      My System SpecsSystem Spec

Change Service Account Passwords

Similar Threads
Thread Forum
Re: Cannot change user passwords in SBS 2003
On Dec 11, 6:18 pm, "kj " <KevinJ....@newsgroup> wrote: Ok, thank you for the reply. The error message when a user tries to change his password...
SBS Server
Help with Script to Change Logon Account of a Service
Can someone give me an example of a script that changes the logon account of a service and then restart the service after changing the logon account...
VB Script
Change Account Credentials (Log On as) on a service?
Hey, Im trying to figure out a way to change the account credentials (username AND password) on a few services on a server. The idea is to remote...
PowerShell
Re: how to change service's user account
http://weblogs.asp.net/avnerk/archive/2007/05/08/setting-windows-service-account-c-and-wmi.aspx --- Shay Levy Windows PowerShell MVP...
PowerShell
how to change service's user account
A service is typically running under a kind of user account, such as "LocalSystem". I want to change a service's user account, but could find how...
PowerShell
How to change passwords in Windows Vista
Until recently I have been getting assistance with my Windows Vista Ultimate through an IM connection, with a file sharing port open between us. I...
Vista General
change passwords
How do i change my main password so i can stop certin ppl from getting on my computer ( i know my old one if thats any help just need to change it)
Vista security

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 18:36.
    .