开发者

Enabling Enable-PSRemoting on Powershell 1.0

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.


You're not going to be able to use PowerShell Remoting in 1.0, but you can use WMI or .Net ServiceController for this task.

$S = Get-WmiObject -Computer $Server -Class win32_service -filter "name='$ServiceName'"
$S.StopService()
$S.StartService()

In fact, if you have 2.0 on the client you're on, you can skip a couple of steps versus the way it's written on either of those posts by using 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'" 

Note: for general remoting, you could set up an SSH server on each box and remote in that way (and set up PowerShell as the default shell), /n software has a pre-built solution around that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜