0
SQL Server服務當前未運行。Powershell - 更改SQL Server服務密碼並啓動服務
我想更改密碼我的本地SQL實例,然後使用PowerShell啓動實例。
我已經使用遠程會話從這個網站(http://www.databasejournal.com/features/mssql/managing-sql-server-services-with-powershell.html) PS建議嘗試 - 當我運行的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
如何更改服務密碼,然後啓動它有什麼建議?
您無法在空值表達式上調用方法。 + CategoryInfo:InvalidOperation:(:) [],RuntimeException的 + FullyQualifiedErrorId:InvokeMethodOnNull + PSComputerName:Laptop123 –
「服務 '的SQL服務器(SQL2008R2_32BIT)(MSSQL $ SQL2008R2_32BIT)' 不能由於啓動以下錯誤:無法啓動服務計算機上的MSSQL $ SQL2008R2_32BIT'。'。 + CategoryInfo:OpenError:(System.ServiceProcess.ServiceController:ServiceController的)[啓動服務],ServiceCommandException + FullyQualifiedErrorId:CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand + PSComputerName:Laptop123' –
剛剛發現這一點,可能是使用給你。希望這將是你所需要的。 http://windowsitpro.com/powershell/changing-service-credentials-using-powershell –