This is in relation to http://www.computerperformance.co.uk/powershell/powershell_remote.htm . Currently, most of the machines in my Test environment are on Powershell 1.0. Under such a scenario, is there a way by which I can still manage to make remote calls via Powershell from one machine to another. My ultimate motive is to start/stop/restart a windows service remotely using Powershell.
问问题
2164 次
1 回答
5
您将无法在 1.0 中使用 PowerShell Remoting,但您可以 使用 WMI或.Net ServiceController来完成此任务。
$S = Get-WmiObject -Computer $Server -Class win32_service -filter "name='$ServiceName'"
$S.StopService()
$S.StartService()
事实上,如果您使用的客户端上有 2.0,则可以跳过几个步骤,而不是使用 Invoke-WMIMethod 在其中任何一篇文章上编写的方式:
Invoke-WMIMethod -Name StopService -Computer $Server -Class win32_service -filter "name='$ServiceName'"
Invoke-WMIMethod -Name StartService -Computer $Server -Class win32_service -filter "name='$ServiceName'"
注意:对于一般远程处理,您可以在每个机器上设置一个 SSH 服务器并以这种方式远程(并将 PowerShell 设置为默认 shell),/n 软件有一个预先构建的解决方案。
于 2011-01-25T15:59:04.600 回答