Skip to content

Instantly share code, notes, and snippets.

@rayterrill
Created July 8, 2016 16:36
Show Gist options
  • Save rayterrill/78aec44412375e25e92c6a62cbad9191 to your computer and use it in GitHub Desktop.
Save rayterrill/78aec44412375e25e92c6a62cbad9191 to your computer and use it in GitHub Desktop.
#requires the winrm gem - sudo gem install -r winrm
require 'winrm'
endpoint = 'http://SERVER_FQDN:5985/wsman'
winrm = WinRM::WinRMWebService.new(endpoint, :negotiate, :user => 'USERNAME', :pass => 'PASSWORD')
winrm.create_executor do |executor|
executor.run_powershell_script("Get-Service | Where-Object {$_.Name -Like '*SQL*'}") do |stdout, stderr|
#executor.run_cmd("ipconfig /all") do |stdout, stderr| #use this if you'd rather run a command prompt
STDOUT.print stdout
STDERR.print stderr
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment