2016-03-15 90 views
0

SQL Server服務當前未運行。Powershell - 更改SQL Server服務密碼並啓動服務

enter image description here

我想更改密碼我的本地SQL實例,然後使用PowerShell啓動實例。

enter image description here

我已經使用遠程會話從這個網站(http://www.databasejournal.com/features/mssql/managing-sql-server-services-with-powershell.htmlPS建議嘗試 - 當我運行的PowerShell ISE 5,我運行它作爲一個管理員。

#Create a new remote PowerShell session and pass in the scrip block to be executed 
$session = New-PSSession -ComputerName Laptop123 -Credential Domain01\User01 
$UserName = "Domain01\User01" # specify user Name here 
$Password = "Password1" # specify Password here 

Invoke-Command -Session $session -ArgumentList $UserName, $Password -Scriptblock { 
     param($UserName, $Password) 
    # Start SQL Server Database engine service (default instance) 
     $Svc = Get-WmiObject win32_service -filter "name='MSSQL$SQL2008R2_32BIT'" 
     $Svc.Change($Null, $Null, $Null, $Null, $Null, $Null, $UserName, $Password) 
     Stop-Service -Name 'MSSQL$SQL2008R2_32BIT' -Force 
    Start-Service 'MSSQL$SQL2008R2_32BIT' 

    # Start SQL Server SQL Server Agent service (default instance) 
     $Svc = Get-WmiObject win32_service -filter "name='SQLAgent$SQL2008R2_32BIT'" 
     $Svc.Change($Null, $Null, $Null, $Null, $Null, $Null, $UserName, $Password) 
     Stop-Service -Name 'SQLAgent$SQL2008R2_32BIT' -Force 
    Start-Service 'SQLAgent$SQL2008R2_32BIT' 
} 

然而,我最終得到了以下錯誤:

Method invocation failed because [System.ServiceProcess.ServiceController] does not contain a method named 'Change'. 
    + CategoryInfo   : InvalidOperation: (:) [], RuntimeException 
    + FullyQualifiedErrorId : MethodNotFound 
    + PSComputerName  : Laptop123 

Service 'SQL Server (SQL2008R2_32BIT) (MSSQL$SQL2008R2_32BIT)' cannot be started due to the following error: Cannot start service MSSQL$SQL2008R2_32BIT on computer '.'. 
    + CategoryInfo   : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException 
    + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand 
    + PSComputerName  : Laptop123 

如何更改服務密碼,然後啓動它有什麼建議?

回答

0

它看起來像你調用腳本中的服務的錯名字嘗試改變名稱過濾器「SQL服務器(SQL2008R2_32BIT)」

讓我知道如果這樣的作品,如果沒有列出任何輸出,你可以接受嘗試。

+0

您無法在空值表達式上調用方法。 + CategoryInfo:InvalidOperation:(:) [],RuntimeException的 + FullyQualifiedErrorId:InvokeMethodOnNull + PSComputerName:Laptop123 –

+0

「服務 '的SQL服務器(SQL2008R2_32BIT)(MSSQL $ SQL2008R2_32BIT)' 不能由於啓動以下錯誤:無法啓動服務計算機上的MSSQL $ SQL2008R2_32BIT'。'。 + CategoryInfo:OpenError:(System.ServiceProcess.ServiceController:ServiceController的)[啓動服務],ServiceCommandException + FullyQualifiedErrorId:CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand + PSComputerName:Laptop123' –

+0

剛剛發現這一點,可能是使用給你。希望這將是你所需要的。 http://windowsitpro.com/powershell/changing-service-credentials-using-powershell –