简体   繁体   English

PowerShell:启动服务和相关服务

[英]PowerShell: Start service and dependent services

I was looking up how to start a service and it's dependent services, and I was reading this site . 我一直在寻找如何启动一项服务及其相关服务的方法,并且正在阅读本网站

It has an example: 它有一个例子:

get-service lanmanserver | Foreach { start-service $_.name -passthru; start-service $_.DependentServices -passthru}

However, when I run the above cmdlet, I get the error: 但是,当我运行上述cmdlet时,出现错误:

Start-Service : Cannot find any service with service name 'System.ServiceProcess.ServiceController'.

Does anybody know why I'm getting this error? 有人知道为什么我会收到此错误吗? Also, I've been using a different way to start a service and it's dependencies: 另外,我一直在使用不同的方式来启动服务及其依赖项:

get-service lanmanserver | select -expand DependentServices | start-service

Any feedback on the workaround? 有关解决方法的任何反馈吗?

Thanks! 谢谢!

This start-service $_.DependentServices returns a collection of services and you're passing it to Start-Service as an argument for the Name parameter (default parameterset's 0th position parameter). start-service $_.DependentServices返回服务集合,您会将其作为Name参数(默认parameterset的第0个位置参数)的参数传递给Start-Service Try this instead: 尝试以下方法:

... Start-Service -InputObject $_.DependentServices -passthru ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM