仅选中“自动”使用 powershell 的服务
我见过很多用于手动停止/启动列表中的服务的脚本,但是如何以编程方式生成该列表(仅是自动服务)。我想编写一些重新启动的脚本,并且正在寻找一种方法来验证所有应该启动的服务是否确实正确启动。
I've seen lots of scripts out there for manually stopping/starting services in a list, but how can I generate that list programatically of -just- the automatic services. I want to script some reboots, and am looking for a way to verify that everything did in fact start up correctly for any services that were supposed to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Get-Service
返回不公开此信息的System.ServiceProcess.ServiceController
对象。因此,您应该使用 WMI 来执行此类任务:Get-WmiObject Win32_Service
。显示所需StartMode
并将输出格式化为 Windows 控制面板的示例:您对自动但未运行的服务感兴趣:
Get-Service
returnsSystem.ServiceProcess.ServiceController
objects that do not expose this information. Thus, you should use WMI for this kind of task:Get-WmiObject Win32_Service
. Example that shows the requiredStartMode
and formats the output a la Windows control panel:You are interested in services that are automatic but not running: