locked
unable to change the password for sql services using powershell script RRS feed

  • Question

  • Hello All,

    I am trying to automate the process of change the passwords for service account. when i run below powershell script i am getting an error.

    Script 

     Try
     {

    [reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.SqlWmiManagement”) | Out-Null  
           $mc = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer localhost

    $sqlInst = $mc.Services['MSSQLSERVER']

     $sqlinst.Stop()
                     $sqlinst.refresh()
           while ($sqlinst.ServiceState -ne "Stopped")  
            {  
            $sqlinst.Refresh()  
            write-host "Stopping the SQL Engine Services"
            $sqlinst.ServiceState  
            }  
            "Service" + $sqlinst.Name + " is now stopped" 

    $sqlInst.ChangePassword("Password@1", "Password@2")
           $sqlInst.Alter()

    $sqlInst.Start() 

    }

    Catch
    {
     $ErrorMessage = $_.Exception.Message
     $FailedItem = $_.Exception.ItemName
     write-host "Error occured while changing the password due to following error message: $ErrorMessage and failed item:$FailedItem "

    }

    Error:

    Error occured while changing the password due to following error message: Exception calling "ChangePassword" with "2" argument(s): "Change service account password failed. " and failed item: 

    Please assist in resolving the error


    • Edited by MSSQLNEW Friday, September 16, 2016 10:51 AM forgot the script
    Friday, September 16, 2016 10:50 AM

All replies

  • Hi MSSQLNEW,

    I have NIL in PS,but see the below links some of the errors talks-

    http://www.sqlhammer.com/automate-service-account-password-changes-with-powershell/
    http://www.morgantechspace.com/2015/03/powershell-change-service-account-username-and-password.html
    http://dba.stackexchange.com/questions/22006/how-to-change-sql-server-service-account-using-ps


    Regards, S_NO "_"

    • Proposed as answer by Teige Gao Thursday, September 29, 2016 9:24 AM
    Friday, September 16, 2016 12:04 PM