使用 Powershell 在没有 WMI 或远程处理的情况下远程停止服务 [英] Using Powershell to stop a service remotely without WMI or remoting
问题描述
我遇到了这个似乎有效的衬垫:
I came across this one liner that appears to work:
stop-service -inputobject $(get-service -ComputerName remotePC -Name Spooler)
谁能解释一下原因,因为我认为除非您使用远程处理或发生在本地主机上,否则停止服务不起作用.
Can anyone explain why, because I thought stop-service didn't work unless you either used remoting or it occurred on the local host.
推荐答案
Get-Service
的输出是一个 System.ServiceProcess.ServiceController
.NET 类,可以操作在远程计算机上.我不知道它是如何实现的 - 可能是 DCOM 或 WMI.一旦您从 Get-Service
获得其中之一,它就可以传递到 Stop-Service
中,它很可能只调用 Stop()
此对象上的方法.这会停止远程机器上的服务.事实上,你也可以这样做:
The output of Get-Service
is a System.ServiceProcess.ServiceController
.NET class that can operate on remote computers. How it accomplishes that, I don't know - probably DCOM or WMI. Once you've gotten one of these from Get-Service
, it can be passed into Stop-Service
which most likely just calls the Stop()
method on this object. That stops the service on the remote machine. In fact, you could probably do this as well:
(get-service -ComputerName remotePC -Name Spooler).Stop()
这篇关于使用 Powershell 在没有 WMI 或远程处理的情况下远程停止服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!