Powershell |将tomcat-Restrat-Process展示为进度栏
有四个Tomcat服务。我想重新启动它,并将状态显示为进度栏。停止4次,开始4次将是8个步骤。我已经尝试了以下操作,但是不幸的是,它没有给出预期的结果。我也不知道该怎么做。有人可以帮我吗?
for ($i = 1; (Get-Service -DisplayName *tomcat*).Count -le 5; $i++ )
{
Write-Progress -Activity "Search in Progress" -Status "$i% Complete:" -PercentComplete $i
Get-Service -DisplayNAme *tomcat* | stop-service -WarningAction SilentlyContinue
}
for ($i = 1; (Get-Service -DisplayName *tomcat*).Count -le 5; $i++ )
{
Write-Progress -Activity "Search in Progress" -Status "$i% Complete:" -PercentComplete $i
Get-Service -DisplayNAme *tomcat* | start-service -WarningAction SilentlyContinue
}
There are four Tomcat services. I would like to restart it and display the status as a progress bar. Stopping 4 times and starting 4 times would be a total of 8 steps. I've tried the following, but unfortunately it doesn't give the expected result. I have no idea how to do it either. Could anyone help me, please?
for ($i = 1; (Get-Service -DisplayName *tomcat*).Count -le 5; $i++ )
{
Write-Progress -Activity "Search in Progress" -Status "$i% Complete:" -PercentComplete $i
Get-Service -DisplayNAme *tomcat* | stop-service -WarningAction SilentlyContinue
}
for ($i = 1; (Get-Service -DisplayName *tomcat*).Count -le 5; $i++ )
{
Write-Progress -Activity "Search in Progress" -Status "$i% Complete:" -PercentComplete $i
Get-Service -DisplayNAme *tomcat* | start-service -WarningAction SilentlyContinue
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么首先要停止服务,然后再循环再次开始呢?
还有一个停止然后开始服务的cmdlet,因此只需要一个循环。
另外,如果您在变量中捕获
get-service
cmdlet的结果,则无需一遍又一遍地这样做:Why first a loop to stop the services and then another loop to start them up again?
There is also a Restart-Service cmdlet that stops and then starts a service, so with that you only need one loop.
Also, if you capture the result of the
Get-Service
cmdlet in a variable, you won't have to do that over and over again: