none
Script help for service account password update...

    Question

  • I'm having trouble getting the below script to work correctly to update service account passwords, I'm wondering if anybody has any insights into what I might have done wrong?

    # ==============================================================================================
    # NAME: Password Reset
    #
    # AUTHOR: Scott Jarboe
    # DATE  : 11/21/2009
    #
    # COMMENT: No intelligence or error handling
    # ==============================================================================================
    #This piece loads VB.Net extensions to allow msgbox input prompt for variable declaration
    [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
    # ==============================================================================================
    #This defines the name of the service account for which you wish to change the password
    $ServiceAccountA = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the name of the service account you wish to modify:", “Service Account Name”);
    $ServiceAccountB = [Microsoft.VisualBasic.Interaction]::InputBox("Re-Enter the name of the service account you wish to modify:", “Service Account Name Validation”);
    If ($ServiceAccountA -ne $ServiceAccountB)
     {
     [Microsoft.VisualBasic.Interaction]::MsgBox("Verification Failure: Account Names did not match.",'OKOnly,Critical,DefaultButton1,SystemModal',"Critical Error.");
     Exit
     }
    # ==============================================================================================
    #This defines the new password that you are changing the service account to
    $NewPasswordA = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the new password for the service account you wish to modify:", “Service Account Password”);
    $NewPasswordB = [Microsoft.VisualBasic.Interaction]::InputBox("Re-Enter the new password for the service account you wish to modify:", “Service Account Password Validation”);
    If ($NewPasswordA -ne $NewPasswordB)
     {
     [Microsoft.VisualBasic.Interaction]::MsgBox("Verification Failure: Passwords did not match.",'OKOnly,Critical,DefaultButton1,SystemModal',"Critical Error.");
     Exit
     }
    # ==============================================================================================
    #This defines the list of servers which you want to update the service password on
    $ServerList = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the complete path of the server list including the filename. For Example: `'C:\scripts\Password_Reset\Serverlist.txt`':", “Server List”);
    $Machines = Get-Content $ServerList
    # ==============================================================================================
    #This is what searches the service accounts and updates as appropriate
    foreach ($Machine in $Machines)
     {
     $Services = GWMI win32_service -Comp $Machine
      foreach ($Service in $Services)
       {
       If ($Service.StartName -eq $ServiceAccountA)
        {
        #Change(
        #  [in]  string DisplayName,
        #  [in]  string PathName,
        #  [in]  uint32 ServiceType,
        #  [in]  uint32 ErrorControl,
        #  [in]  string StartMode,
        #  [in]  boolean DesktopInteract,
        #  [in]  string StartName,
        #  [in]  string StartPassword,
        #  [in]  string LoadOrderGroup,
        #  [in]  string LoadOrderGroupDependencies,
        #  [in]  string ServiceDependencies
        $Service.Change( , , , , , , , '$NewPasswordA');
        $Service.StopService();
        $Service.SetInfo();
        $Service.StartService();
        }
       Else
        {
        Write-Host "This is not the service you are looking for."
        }
       }
     }
     
     
    Wednesday, December 09, 2009 9:56 PM

Answers

  • Hi,
    Try to replace

    $Service.Change( , , , , , , , '$NewPasswordA');

    with

    $Service.Change($null, $null, $null, $null, $null, $null, $null, $NewPasswordA)

    You might also find the following script useful.
    Wednesday, December 09, 2009 10:23 PM
  • $Service.Change( , , , , , , , '$NewPasswordA');

    this is common mistake when you place variable into single quotes. In that case variables are not expanded to their value. To expand variables you need to use double quotes or just not use qotes.
    http://www.sysadmins.lv
    Thursday, December 10, 2009 6:49 AM

All replies

  • Hi,
    Try to replace

    $Service.Change( , , , , , , , '$NewPasswordA');

    with

    $Service.Change($null, $null, $null, $null, $null, $null, $null, $NewPasswordA)

    You might also find the following script useful.
    Wednesday, December 09, 2009 10:23 PM
  • $Service.Change( , , , , , , , '$NewPasswordA');

    this is common mistake when you place variable into single quotes. In that case variables are not expanded to their value. To expand variables you need to use double quotes or just not use qotes.
    http://www.sysadmins.lv
    Thursday, December 10, 2009 6:49 AM