This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

How do I restart a service based on alerting from a Windows Powershell Script Monitor?

I built the monitor that I want with a Powershell script that returns Up, Warning, Down, Unknown based on Event log entries. I want the alert to watch for a status that's not up, then restart the 'File Replication Service' or 'NtFrs' on the target server. How do I restart a service based on alerting from a Windows Powershell Script Monitor?

  • So, this is a version of script that works from the monitoring server in an elevated cmd prompt.

    Powershell "Restart-Service -InputObject (Get-Service -name 'file replication service' -ComputerName Server)"

    And these are versions of the script that don't work in the Alert simulation

    Powershell "Restart-Service -InputObject (Get-Service -name 'file replication service' -ComputerName ${N=SwisEntity;M=Application.Node.DNS})"

    Powershell "Restart-Service -InputObject (Get-Service -name 'file replication service' -ComputerName Server)"

  • This is working! Thank you aLTeReGo for previous posts. Here are my notes in case someone else has a simmilar question.

    aLTeReGo's steps for methodical troubleshooting of script in alert action (my summary)

    • Run the desired script as interactive user on the Orion server with hard coded values
      • User should match the defined user that will be used in the alert action
    • Run a simple script (perhaps '[Environment]::UserName | Out-File c:\result.txt') in the alert action
      • Define an appropriate user with access to network resources as needed
    • Run the desired script in the alert action with hard coded values
      • using the same defined user
    • Run the desired script in the alert action with appropriate variables

      Alert Action using powershell scripthttps://thwack.solarwinds.com/thread/23475

        "PowerShell script alert action fails: Exit code 3221225794"

        Open Control Panel, and then go to Administrative Tools > Computer Settings > Windows Settings > Security Settings > Local Policies > Security Options.

        Locate and turn off the User Account Control: Run all administrators in Admin Approval Mode policy.

    From <https://support.solarwinds.com/Success_Center/Network_Performance_Monitor_(NPM)/PowerShell_script_alert_action_fails_Exit_code_3221225794>

    aLTeReGo

    aLTeReGo

    Sep 10, 2015 12:54 PM (in response to cbunge)

    PowerShell is a fickle little *****, er.. I mean princess. It's not possible to execute 64bit PowerShell from within a 32bit process like the Orion Alert service. As such you will need to call the 32bit PowerShell.exe from your command line. The 32bit version PowerShell can be found under %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe.

    Alert Action using powershell scripthttps://thwack.solarwinds.com/thread/23475