【发布时间】:2019-05-07 10:21:17
【问题描述】:
我有一个简单的脚本,可以停止/启动远程服务器上的多个服务。它工作正常,但每隔一次运行我都会看到以下错误。但即使它说它不能停止服务,实际上它也会停止它。我尝试在不同服务之间添加一些暂停时间,但这似乎没有帮助。
这就是它停止服务的方式
Get-Service -ComputerName SERVER1 -Name SERVICE1 | Stop-Service -Force
这是完全错误
Stop-Service : Service 'SERVICE1 (SERVICE1)' cannot be stopped due to the following error: Cannot
stop SERVICE1 service on computer 'SERVER1'.
At C:\Script\dev1_stop.ps1:25 char:67
+ ... puterName SERVER1 -Name SERVICE1 | Stop-Service -Force
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (System.ServiceProcess.ServiceController:ServiceController) [Stop-Service],
ServiceCommandException
+ FullyQualifiedErrorId : CouldNotStopService,Microsoft.PowerShell.Commands.StopServiceCommand
【问题讨论】:
标签: powershell windows-services