【发布时间】:2016-10-18 09:16:51
【问题描述】:
我必须停止多个服务,检查服务是否正确停止,然后运行多个批处理文件。批处理作业完成后,首先重新启动已停止的服务。我启动了以下脚本,但无法继续。
#Define Services
$service1 = 'StiSvc'
$service2 = 'AdobeARMservice'
$services = @(
$service1,
$service2
)
#Stop Services
Get-Service |
Where { $services -contains $_.Name } |
Foreach {
$_ | Stop-Service
}
#Verify Services
Get-Service |
Where { $services -contains $_.Name } |
Foreach {
if ((Get-Service $_.Name).Status -eq "stopped") {
Write-Host 'Service Stop Pass (0)'
} else {
Write-Host 'Service Stop Failed (1000)';
exit '1000'
}
}
#Start batch
if ($services.Status -eq "Stopped") {
Start-Process "cmd.exe" "/c C:\download\hello.bat"
} else {
Start-Sleep -s 10
}
【问题讨论】:
-
真正的问题是什么?
-
那么,您的问题是什么?什么没有按预期工作?你“不能走得更远”……怎么办?
-
它没有按预期工作。服务停止,但批处理文件未启动。
-
尝试使用调用操作符来运行批处理文件:
& "C:\download\hello.bat"(就像那样,没有Start-Process或cmd /c) -
我试过了,但到目前为止没有任何乐趣。
标签: windows powershell batch-file