Forum Discussion

Tim_King's avatar
4 years ago

Run an Ad Hoc PowerShell Command?

Is it possible to run a PowerShell command as needed without having to script out a datasource?

We have a 3rd party program running on the collector that periodically needs the Windows service restarted in order to apply an update.  I have over 50 collectors that we need to do this on a regular basis.  If I can accomplish this using the remote capabilities of LogicMonitor, it would be great.

I'm just looking to be able to run the PS command:        Stop-Service "servicename"     then confirm on a web portal that it is not communicating,   then send the command   Start-Service "servicename"

 

 

  • Anonymous's avatar
    Anonymous

    Sounds like you're looking for an orchestration tool. Ansible would fit this bill pretty nicely. The debug command would also work for you, but would almost be as rough as logging into each one.

    Powershell has remoting capabilities. You could script the whole thing in powershell, then do a for loop to get through each server you want to restart the service on.

  • Check Mike Suding's blog page -- lots of cool stuff, including this. A bit old, but probably still works :).

    http://blog.mikesuding.com/2016/09/20/restart-a-service-alert-if-restart-fails/

    As far as the debugger, yeah -- that stuff freaks me out a lot given that LM more or less requires Domain Admins on collectors (really should be Performance Monitoring Users, especially after the recent SolarWinds incident).  You can run those debugger commands from the API as well, even more scary.

  • You can use the !posh DEBUG command on the collector:

    https://www.logicmonitor.com/support/collectors/collector-troubleshooting/using-the-collector-debug-facility