PowerShell执行SSRS重启脚本报错‘Cannot open...’求助
SSRS重启脚本执行错误排查
问题描述
我不熟悉PowerShell,编写了控制SSRS重启的脚本,内容如下:
Stop-Service "SQLServerReportingServices" Start-Service "SQLServerReportingServices"
在PowerShell导航到脚本目录执行.\MyPSScript.ps1时,报错:Cannot open SQLServerReportingServices service on computer '.',完整错误信息如下:
Stop-Service : Service 'SQL Server Reporting Services (SQLServerReportingServices)' cannot be stopped following error: Cannot open SQLServerReportingServices service on computer '.'. At C:\SSRS_Restart.ps1:1 char:1 + Stop-Service "SQLServerReportingServices" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (System.ServiceProcess.ServiceController:ServiceController) ServiceCommandException + FullyQualifiedErrorId : CouldNotStopService,Microsoft.PowerShell.Commands.StopServiceCommand Start-Service : Service 'SQL Server Reporting Services (SQLServerReportingServices)' cannot be started following error: Cannot open SQLServerReportingServices service on computer '.'. At C:\SSRS_Restart.ps1:2 char:1 + Start-Service "SQLServerReportingServices" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [ ServiceCommandException + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand
错误原因及解决方法
1. 服务名称不正确
你使用的SQLServerReportingServices可能不是系统中实际的SSRS服务名称。不同SSRS版本的服务命名有差异:
- SSRS 2008/2008 R2默认服务名是
ReportServer - 2016及以后版本通常是
SQLServerReportingServices,但如果是命名实例,服务名会带实例后缀(比如SQLServerReportingServices$INSTANCE_NAME)
验证步骤:
打开PowerShell执行以下命令,查看所有和报表服务相关的条目:
Get-Service | Where-Object {$_.DisplayName -match "Report"}
找到结果里的Name字段,这才是你需要在脚本中使用的正确服务名。
2. 权限不足
重启系统服务需要管理员权限,当前PowerShell窗口可能未以管理员身份运行。
解决步骤:
右键点击PowerShell图标,选择「以管理员身份运行」,再执行你的脚本。
3. 服务未安装或未注册
如果上述命令没有返回任何SSRS相关服务,说明SSRS可能未安装,或者服务被禁用、未正确注册,需要检查SSRS的安装状态。
修正后的脚本示例
假设通过Get-Service查到正确服务名为ReportServer,脚本修改为:
Stop-Service "ReportServer" Start-Service "ReportServer"
如果需要确保服务完全停止后再启动,可以添加等待逻辑:
Stop-Service "ReportServer" -Force # 循环等待服务停止 do { Start-Sleep -Seconds 2 $service = Get-Service "ReportServer" } while ($service.Status -ne "Stopped") Start-Service "ReportServer"
内容的提问来源于stack exchange,提问作者bmurrell30
相关产品推荐
相关产品推荐

