【问题标题】:Powershell - Change SQL Server Service Password and Start ServicePowershell - 更改 SQL Server 服务密码并启动服务
【发布时间】:2016-03-15 15:46:57
【问题描述】:

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

关于如何更改服务密码然后启动它有什么建议吗?

【问题讨论】:

    标签: powershell service


    【解决方案1】:

    您似乎在脚本中调用了错误的服务名称尝试将名称过滤器更改为“SQL Server (SQL2008R2_32BIT)”

    让我知道这是否有效,如果没有列出您尝试该方法可能会收到的任何输出。

    【讨论】:

    • 您不能在空值表达式上调用方法。 + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull + PSComputerName : Laptop123
    • '服务'SQL Server (SQL2008R2_32BIT) (MSSQL$SQL2008R2_32BIT)'由于以下错误无法启动:无法在计算机'.'上启动服务MSSQL$SQL2008R2_32BIT。 + CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand + PSComputerName : Laptop123'
    • 刚找到这个,可能对你有用。希望这正是您所需要的。 windowsitpro.com/powershell/…
    • 确保服务未处于禁用模式。将服务设置为自动或手动模式,然后尝试启动服务
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    相关资源
    最近更新 更多