Created
April 28, 2014 19:56
-
-
Save drgarcia1986/11382359 to your computer and use it in GitHub Desktop.
Scripts for Start/Stop Windows service remote (bath or powershell)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
net use \\%Machine% [PasswordOfRemoteMachine] /USER:[UserOfRemoteMachine] | |
sc \\%Machine% %Action% %Service% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Action: Start|Stop | |
Service: Service name | |
Machine: Remote machine host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$action = $env:Action + "Service" | |
$service = $env:Service | |
$machine = $env:Machine | |
$passwd = ConvertTo-SecureString "[PasswordOfRemoteMachine]" -AsPlainText -Force | |
$credential = New-Object System.Management.Automation.PSCredential("[UserOfRemoteMachine]", $passwd) | |
(Get-WmiObject -computer $machine Win32_Service -Filter "Name='$service'" -Credential $credential).InvokeMethod($action,$null).ReturnValue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment