开发者

Not able to start and stop service from remote machine

开发者 https://www.devze.com 2023-03-25 16:53 出处:网络
We have some winodow services on the remote machine. I am not able to start and stop that services usin开发者_开发知识库g service controller from my machine.You can use Powershell and supply it with t

We have some winodow services on the remote machine. I am not able to start and stop that services usin开发者_开发知识库g service controller from my machine.


You can use Powershell and supply it with the appropriate credentials:

PS C:\Users\YourUserName>$remoteComp = "remoteComputerName"
PS C:\Users\YourUserName>$svc = "Service Name"
PS C:\Users\YourUserName>$c = Get-Credential
PS C:\Users\YourUserName>$obj = (gwmi -computername $comp -class Win32_Service -computer $remoteComp -Credential $c | Where-Object { $_.Name -match "^$svc*" }

Now you can use $obj to stop and start the service

PS C:\Users\YourUserName>$obj.StopService()
PS C:\Users\YourUserName>$obj.StartService()

In addition, if you want to see the methods and properties available for $obj use this command:

PS C:\Users\YourUserName>$obj | Get-Member
0

精彩评论

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