Get-Service cmdlet 具有两个在服务管理中非常有用的参数。 DependentServices 参数获取依赖于该服务的服务。 RequiredServices 参数获取此服务所依赖的服务。
这些参数只显示 Get-Service 返回的 System.ServiceProcess.ServiceController 对象的 DependentServices 和 ServicesDependedOn (alias=RequiredServices) 属性的值,但是它们可简化命令,使获取此信息更加简单。
下面的命令获取 LanmanWorkstation 服务需要的服务。
PS C:/Users/maxsu> Get-Service -Name LanmanWorkstation -RequiredServices
Status Name DisplayName
------ ---- -----------
Running NSI Network Store Interface Service
Running MRxSmb20 SMB 2.0 MiniRedirector
Running Bowser 浏览器
下面的命令获取需要 LanmanWorkstation 服务的服务。
PS C:/Users/maxsu> Get-Service -Name LanmanWorkstation -DependentServices
Status Name DisplayName
------ ---- -----------
Running VMwareHostd VMware Workstation Server
Running SessionEnv Remote Desktop Configuration
Stopped Netlogon Netlogon
甚至可以获取所有具有依赖关系的服务。 下面的命令所做的就是这些,然后使用 Format-Table cmdlet 来显示计算机上服务的 Status、Name、RequiredServices 和 DependentServices 属性。
PS C:/Users/maxsu> Get-Service -Name * | Where-Object {$_.RequiredServices -or $_.DependentServices} |
Format-Table -Property Status, Name, RequiredServices, DependentServices -auto
Status Name RequiredServices DependentServices
------ ---- ---------------- -----------------
Stopped AppIDSvc {RpcSs, CryptSvc, AppID} {applockerfltr}
Running Appinfo {RpcSs, ProfSvc} {}
Stopped Apple Mobile Device Service {Tcpip} {}
Stopped AppXSvc {rpcss, staterepository} {}
Running AudioEndpointBuilder {} {AarSvc_3c08b731, AarSvc, A...
Running Audiosrv {AudioEndpointBuilder, RpcSs} {AarSvc_3c08b731, AarSvc}
Stopped autotimesvc {rpcss} {}
Stopped AxInstSV {rpcss} {}
Running BFE {RpcSs}
Stopped BITS {RpcSs} {}
Running BrokerInfrastructure {DcomLaunch, RpcSs, RpcEptMapper}
Stopped BTAGService {rpcss} {}
Running BthAvctpSvc {rpcss} {}
Stopped bthserv {} {BluetoothUserService_3c08b...
Running CDPSvc {Tcpip, ncbservice, RpcSS} {}
Running CertPropSvc {RpcSs} {}
Stopped ClipSVC {rpcss} {}
Stopped COMSysApp {EventSystem, SENS, RpcSs} {}
Running CoreMessagingRegistrar {rpcss} {}
Running cphs {RPCSS} {}
Running CryptSvc {RpcSs} {applockerfltr, AppIDSvc}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266809.html