1 Reply Latest reply on Dec 13, 2011 1:27 PM by northben

    Help with Powershell

    cballmannatech

      I have written a short Powershell script that goes out, checks a com object for availability, and restarts it if it is shut down.

      I can run the script using runas, can run it interactively, and never have a problem. When the powershell script is invoked from IPmonitor, powershell starts for a short time and seems to close without ever running the script, and IPMonitor returns no error code, nor is anything logged in the various log locations/event viewer that powershell ever started with the credentials I am passing it.

      I am attaching the config for the monitor, as well as the script itself. I can honestly say that I have tried nearly everything I can think of to get this to work - various command-line paramaters, changes to the directories, even multiple user accounts with varying levels of permissions, and all have failed.

      Executable Name powershell.exe
      Directory c:\windows\system32\WindowsPowerShell\v1.0
      Command Line Parameters -file c:\scripts\checkdetailexebroker.ps1
      Startup Directory c:\windows\system32\WindowsPowerShell\v1.0\




      $remotemachine = "USHQCOMPLUS03"
      $EmailPDF = "EmailPDF"
      $CheckDetailExeBroker = "CheckDetailExeBroker"
      $comObj = New-Object -comobject COMAdmin.COMAdminCatalog



      $DLL=Get-WmiObject win32_process -computername $remotemachine -filter "Name = 'dllhost.exe' " | foreach-object { $_.CommandLine } | where-object { $_ -match "D2EAE3E6-9A00-4395-8953-3EEFDB0C1AB5|AC799898-ED26-4DCA-B1A6-DFA4FB4052AE" }
      if ($DLL|where-object { $_ -match "AC799898-ED26-4DCA-B1A6-DFA4FB4052AE" }) {""}
      else {"CheckDetailExeBroker on $remotemachine is not running, sending restart command"
             $comObj.Connect($RemoteMachine)
             $comObj.StartApplication($CheckDetailExeBroker)}
             
      Start-sleep -s 10
             

      $DLL=Get-WmiObject win32_process -computername $remotemachine -filter "Name = 'dllhost.exe' " | foreach-object { $_.CommandLine } | where-object { $_ -match "D2EAE3E6-9A00-4395-8953-3EEFDB0C1AB5|AC799898-ED26-4DCA-B1A6-DFA4FB4052AE" }
      if ($DLL|where-object { $_ -match "AC799898-ED26-4DCA-B1A6-DFA4FB4052AE" }) {"$CheckDetailExeBroker on $remotemachine is running"}
      else {"$CheckDetailExeBroker on $remotemachine did not successfully restart"
              exit 1}

       

      If anyone can help me with this, I would hugely appreciate it.

       

      Chuck Ball

        • Re: Help with Powershell
          northben

          In the unlikely event that you still have this question, or in the more likely event that someone else has this same question, I think you are looking for page 232 of the APM Administrator Guide.

          Specifically, in your WMI query add:

          -credential '${credential}'