Skip to content

Instantly share code, notes, and snippets.

@drgarcia1986
Created April 28, 2014 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drgarcia1986/11382359 to your computer and use it in GitHub Desktop.
Save drgarcia1986/11382359 to your computer and use it in GitHub Desktop.
Scripts for Start/Stop Windows service remote (bath or powershell)
net use \\%Machine% [PasswordOfRemoteMachine] /USER:[UserOfRemoteMachine]
sc \\%Machine% %Action% %Service%
Action: Start|Stop
Service: Service name
Machine: Remote machine host
$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