2016-03-15 62 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 –