Powershell-更改SQL Server服务密码并启动服务

Powershell-更改SQL Server服务密码并启动服务,powershell,service,Powershell,Service,SQL Server服务当前未运行 我正在尝试更改本地SQL实例的密码,然后使用PowerShell启动该实例 我已尝试使用此站点建议的远程会话() PS-当我运行PowerShell ISE 5时,我是以管理员的身份运行它。 #Create a new remote PowerShell session and pass in the scrip block to be executed $session = New-PSSession -ComputerName Laptop123

SQL Server服务当前未运行

我正在尝试更改本地SQL实例的密码,然后使用PowerShell启动该实例

我已尝试使用此站点建议的远程会话() 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

有关如何更改服务密码然后启动它的任何建议?

看起来您在脚本中调用了错误的服务名称,请尝试将名称筛选器更改为“SQL Server(SQL2008R2_32BIT)”


让我知道这是否有效,如果不列出您可能从尝试中收到的任何输出。

您不能对空值表达式调用方法。+CategoryInfo:InvalidOperation:(:)[],RuntimeException+FullyQualifiedErrorId:InvokeMethodonFull+PSComputerName:Laptop123'Service'SQL Server(SQL2008R2_32BIT)(MSSQL$SQL2008R2_32BIT)'由于以下错误而无法启动:无法在计算机上启动服务MSSQL$SQL2008R2_32BIT'CategoryInfo:OpenError:(System.ServiceProcess.ServiceController:ServiceController)[启动服务],ServiceCommandException+FullyQualifiedErrorId:CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand+PSComputerName:Laptop123'刚刚发现此,可能对您有用。希望这正是你需要的。确保服务未处于禁用模式。将服务设置为自动或手动模式,然后尝试启动服务